Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace Log Level Defines #23

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ArduinoLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void Logging::begin(int level, Print* logOutput, bool showLevel)
void Logging::setLevel(int level)
{
#ifndef DISABLE_LOGGING
_level = constrain(level, LOG_LEVEL_SILENT, LOG_LEVEL_VERBOSE);
_level = constrain(level, ARDUINO_LOG_LOG_LEVEL_SILENT, ARDUINO_LOG_LOG_LEVEL_VERBOSE);
#endif
}

Expand Down Expand Up @@ -172,12 +172,12 @@ void Logging::printFormat(const char format, va_list *args) {
}
else if (format == 's')
{
register char *s = va_arg(*args, char *);
char *s = va_arg(*args, char *);
_logOutput->print(s);
}
else if (format == 'S')
{
register __FlashStringHelper *s = va_arg(*args, __FlashStringHelper *);
__FlashStringHelper *s = va_arg(*args, __FlashStringHelper *);
_logOutput->print(s);
}
else if (format == 'd' || format == 'i')
Expand All @@ -196,15 +196,15 @@ void Logging::printFormat(const char format, va_list *args) {
{
_logOutput->print("0x");
//_logOutput->print(va_arg(*args, int), HEX);
register uint16_t h = (uint16_t) va_arg( *args, int );
uint16_t h = (uint16_t) va_arg( *args, int );
if (h<0xFFF) _logOutput->print('0');
if (h<0xFF ) _logOutput->print('0');
if (h<0xF ) _logOutput->print('0');
_logOutput->print(h,HEX);
}
else if (format == 'p')
{
register Printable *obj = (Printable *) va_arg(*args, int);
Printable *obj = (Printable *) va_arg(*args, int);
_logOutput->print(*obj);
}
else if (format == 'b')
Expand All @@ -229,7 +229,7 @@ void Logging::printFormat(const char format, va_list *args) {
_logOutput->print((char) va_arg(*args, int));
}
else if( format == 'C' ) {
register char c = (char) va_arg( *args, int );
char c = (char) va_arg( *args, int );
if (c>=0x20 && c<0x7F) {
_logOutput->print(c);
} else {
Expand Down
86 changes: 43 additions & 43 deletions ArduinoLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ typedef void (*printfunction)(Print*, int);
// ************************************************************************
//#define DISABLE_LOGGING

#define LOG_LEVEL_SILENT 0
#define LOG_LEVEL_FATAL 1
#define LOG_LEVEL_ERROR 2
#define LOG_LEVEL_WARNING 3
#define LOG_LEVEL_INFO 4
#define LOG_LEVEL_NOTICE 4
#define LOG_LEVEL_TRACE 5
#define LOG_LEVEL_VERBOSE 6

#define CR "\n"
#define LF "\r"
#define NL "\n\r"
#define ARDUINO_LOG_LOG_LEVEL_SILENT 0
#define ARDUINO_LOG_LOG_LEVEL_FATAL 1
#define ARDUINO_LOG_LOG_LEVEL_ERROR 2
#define ARDUINO_LOG_LOG_LEVEL_WARNING 3
#define ARDUINO_LOG_LOG_LEVEL_INFO 4
#define ARDUINO_LOG_LOG_LEVEL_NOTICE 4
#define ARDUINO_LOG_LOG_LEVEL_TRACE 5
#define ARDUINO_LOG_LOG_LEVEL_VERBOSE 6

#define CR "\r"
#define LF "\n"
#define NL "\r\n"
#define LOGGING_VERSION 1_0_4

/**
Expand Down Expand Up @@ -78,14 +78,14 @@ typedef void (*printfunction)(Print*, int);
*
* ---- Loglevels
*
* 0 - LOG_LEVEL_SILENT no output
* 1 - LOG_LEVEL_FATAL fatal errors
* 2 - LOG_LEVEL_ERROR all errors
* 3 - LOG_LEVEL_WARNING errors and warnings
* 4 - LOG_LEVEL_INFO errors, warnings and notices
* 4 - LOG_LEVEL_NOTICE Same as INFO, kept for backward compatibility
* 5 - LOG_LEVEL_TRACE errors, warnings, notices, traces
* 6 - LOG_LEVEL_VERBOSE all
* 0 - ARDUINO_LOG_LOG_LEVEL_SILENT no output
* 1 - ARDUINO_LOG_LOG_LEVEL_FATAL fatal errors
* 2 - ARDUINO_LOG_LOG_LEVEL_ERROR all errors
* 3 - ARDUINO_LOG_LOG_LEVEL_WARNING errors and warnings
* 4 - ARDUINO_LOG_LOG_LEVEL_INFO errors, warnings and notices
* 4 - ARDUINO_LOG_LOG_LEVEL_NOTICE Same as INFO, kept for backward compatibility
* 5 - ARDUINO_LOG_LOG_LEVEL_TRACE errors, warnings, notices, traces
* 6 - ARDUINO_LOG_LOG_LEVEL_VERBOSE all
*/

class Logging
Expand All @@ -96,7 +96,7 @@ class Logging
*/
Logging()
#ifndef DISABLE_LOGGING
: _level(LOG_LEVEL_SILENT),
: _level(ARDUINO_LOG_LOG_LEVEL_SILENT),
_showLevel(true),
_logOutput(NULL)
#endif
Expand Down Expand Up @@ -182,142 +182,142 @@ class Logging
* Output a fatal error message. Output message contains
* F: followed by original message
* Fatal error messages are printed out at
* loglevels >= LOG_LEVEL_FATAL
* loglevels >= ARDUINO_LOG_LOG_LEVEL_FATAL
*
* \param msg format string to output
* \param ... any number of variables
* \return void
*/
template <class T, typename... Args> void fatal(T msg, Args... args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_FATAL, false, msg, args...);
printLevel(ARDUINO_LOG_LOG_LEVEL_FATAL, false, msg, args...);
#endif
}

template <class T, typename... Args> void fatalln(T msg, Args... args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_FATAL, true, msg, args...);
printLevel(ARDUINO_LOG_LOG_LEVEL_FATAL, true, msg, args...);
#endif
}

/**
* Output an error message. Output message contains
* E: followed by original message
* Error messages are printed out at
* loglevels >= LOG_LEVEL_ERROR
* loglevels >= ARDUINO_LOG_LOG_LEVEL_ERROR
*
* \param msg format string to output
* \param ... any number of variables
* \return void
*/
template <class T, typename... Args> void error(T msg, Args... args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_ERROR, false, msg, args...);
printLevel(ARDUINO_LOG_LOG_LEVEL_ERROR, false, msg, args...);
#endif
}

template <class T, typename... Args> void errorln(T msg, Args... args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_ERROR, true, msg, args...);
printLevel(ARDUINO_LOG_LOG_LEVEL_ERROR, true, msg, args...);
#endif
}
/**
* Output a warning message. Output message contains
* W: followed by original message
* Warning messages are printed out at
* loglevels >= LOG_LEVEL_WARNING
* loglevels >= ARDUINO_LOG_LOG_LEVEL_WARNING
*
* \param msg format string to output
* \param ... any number of variables
* \return void
*/
template <class T, typename... Args> void warning(T msg, Args...args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_WARNING, false, msg, args...);
printLevel(ARDUINO_LOG_LOG_LEVEL_WARNING, false, msg, args...);
#endif
}

template <class T, typename... Args> void warningln(T msg, Args...args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_WARNING, true, msg, args...);
printLevel(ARDUINO_LOG_LOG_LEVEL_WARNING, true, msg, args...);
#endif
}

/**
* Output a notice message. Output message contains
* N: followed by original message
* Notice messages are printed out at
* loglevels >= LOG_LEVEL_NOTICE
* loglevels >= ARDUINO_LOG_LOG_LEVEL_NOTICE
*
* \param msg format string to output
* \param ... any number of variables
* \return void
*/
template <class T, typename... Args> void notice(T msg, Args...args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_NOTICE, false, msg, args...);
printLevel(ARDUINO_LOG_LOG_LEVEL_NOTICE, false, msg, args...);
#endif
}

template <class T, typename... Args> void noticeln(T msg, Args...args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_NOTICE, true, msg, args...);
printLevel(ARDUINO_LOG_LOG_LEVEL_NOTICE, true, msg, args...);
#endif
}

template <class T, typename... Args> void info(T msg, Args...args) {
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_INFO, false, msg, args...);
printLevel(ARDUINO_LOG_LOG_LEVEL_INFO, false, msg, args...);
#endif
}

template <class T, typename... Args> void infoln(T msg, Args...args) {
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_INFO, true, msg, args...);
printLevel(ARDUINO_LOG_LOG_LEVEL_INFO, true, msg, args...);
#endif
}

/**
* Output a trace message. Output message contains
* N: followed by original message
* Trace messages are printed out at
* loglevels >= LOG_LEVEL_TRACE
* loglevels >= ARDUINO_LOG_LOG_LEVEL_TRACE
*
* \param msg format string to output
* \param ... any number of variables
* \return void
*/
template <class T, typename... Args> void trace(T msg, Args... args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_TRACE, false, msg, args...);
printLevel(ARDUINO_LOG_LOG_LEVEL_TRACE, false, msg, args...);
#endif
}

template <class T, typename... Args> void traceln(T msg, Args... args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_TRACE, true, msg, args...);
printLevel(ARDUINO_LOG_LOG_LEVEL_TRACE, true, msg, args...);
#endif
}

/**
* Output a verbose message. Output message contains
* V: followed by original message
* Debug messages are printed out at
* loglevels >= LOG_LEVEL_VERBOSE
* loglevels >= ARDUINO_LOG_LOG_LEVEL_VERBOSE
*
* \param msg format string to output
* \param ... any number of variables
* \return void
*/
template <class T, typename... Args> void verbose(T msg, Args... args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_VERBOSE, false, msg, args...);
printLevel(ARDUINO_LOG_LOG_LEVEL_VERBOSE, false, msg, args...);
#endif
}

template <class T, typename... Args> void verboseln(T msg, Args... args){
#ifndef DISABLE_LOGGING
printLevel(LOG_LEVEL_VERBOSE, true, msg, args...);
printLevel(ARDUINO_LOG_LOG_LEVEL_VERBOSE, true, msg, args...);
#endif
}

Expand All @@ -342,9 +342,9 @@ class Logging
{
return;
}
if (level < LOG_LEVEL_SILENT)
if (level < ARDUINO_LOG_LOG_LEVEL_SILENT)
{
level = LOG_LEVEL_SILENT;
level = ARDUINO_LOG_LOG_LEVEL_SILENT;
}


Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ This package has been published to the Arduino & PlatformIO package managers, bu
Serial.begin(9600);

// Initialize with log level and log output.
Log.begin (LOG_LEVEL_VERBOSE, &Serial);
Log.begin (ARDUINO_LOG_LOG_LEVEL_VERBOSE, &Serial);

// Start logging text and formatted values
Log.errorln ( "Log as Error with binary values : %b, %B" , 23 , 345808);
Expand All @@ -68,19 +68,19 @@ begin(int level, Print* logOutput)
The loglevels available are

```
* 0 - LOG_LEVEL_SILENT no output
* 1 - LOG_LEVEL_FATAL fatal errors
* 2 - LOG_LEVEL_ERROR all errors
* 3 - LOG_LEVEL_WARNING errors, and warnings
* 4 - LOG_LEVEL_NOTICE errors, warnings and notices
* 5 - LOG_LEVEL_TRACE errors, warnings, notices & traces
* 6 - LOG_LEVEL_VERBOSE all
* 0 - ARDUINO_LOG_LOG_LEVEL_SILENT no output
* 1 - ARDUINO_LOG_LOG_LEVEL_FATAL fatal errors
* 2 - ARDUINO_LOG_LOG_LEVEL_ERROR all errors
* 3 - ARDUINO_LOG_LOG_LEVEL_WARNING errors, and warnings
* 4 - ARDUINO_LOG_LOG_LEVEL_NOTICE errors, warnings and notices
* 5 - ARDUINO_LOG_LOG_LEVEL_TRACE errors, warnings, notices & traces
* 6 - ARDUINO_LOG_LOG_LEVEL_VERBOSE all
```

example

```
Log.begin(LOG_LEVEL_ERROR, &Serial, true);
Log.begin(ARDUINO_LOG_LOG_LEVEL_ERROR, &Serial, true);
```

if you want to fully remove all logging code, uncomment `#define DISABLE_LOGGING` in `ArduinoLog.h`, this may significantly reduce your sketch/library size.
Expand Down
2 changes: 1 addition & 1 deletion examples/Log-advanced/Log-advanced.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void setup() {

Log.setPrefix(printPrefix); // set prefix similar to NLog
Log.setSuffix(printSuffix); // set suffix
Log.begin(LOG_LEVEL_VERBOSE, &Serial);
Log.begin(ARDUINO_LOG_LOG_LEVEL_VERBOSE, &Serial);
Log.setShowLevel(false); // Do not show loglevel, we will do this in the prefix
}

Expand Down
4 changes: 2 additions & 2 deletions examples/Log-basic/Log-basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ void setup() {
randomSeed(analogRead(0));
// Pass log level, whether to show log level, and print interface.
// Available levels are:
// LOG_LEVEL_SILENT, LOG_LEVEL_FATAL, LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, LOG_LEVEL_INFO, LOG_LEVEL_TRACE, LOG_LEVEL_VERBOSE
// ARDUINO_LOG_LOG_LEVEL_SILENT, ARDUINO_LOG_LOG_LEVEL_FATAL, ARDUINO_LOG_LOG_LEVEL_ERROR, ARDUINO_LOG_LOG_LEVEL_WARNING, ARDUINO_LOG_LOG_LEVEL_INFO, ARDUINO_LOG_LOG_LEVEL_TRACE, ARDUINO_LOG_LOG_LEVEL_VERBOSE
// Note: if you want to fully remove all logging code, uncomment #define DISABLE_LOGGING in Logging.h
// this will significantly reduce your project size

Log.begin(LOG_LEVEL_VERBOSE, &Serial);
Log.begin(ARDUINO_LOG_LOG_LEVEL_VERBOSE, &Serial);


//Start logging
Expand Down
6 changes: 3 additions & 3 deletions examples/platformio-basic/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ void setup() {
randomSeed(analogRead(0));
// Pass log level, whether to show log level, and print interface.
// Available levels are:
// LOG_LEVEL_SILENT, LOG_LEVEL_FATAL, LOG_LEVEL_ERROR, LOG_LEVEL_WARNING,
// LOG_LEVEL_NOTICE, LOG_LEVEL_TRACE, LOG_LEVEL_VERBOSE Note: if you want to
// ARDUINO_LOG_LOG_LEVEL_SILENT, ARDUINO_LOG_LOG_LEVEL_FATAL, ARDUINO_LOG_LOG_LEVEL_ERROR, ARDUINO_LOG_LOG_LEVEL_WARNING,
// ARDUINO_LOG_LOG_LEVEL_NOTICE, ARDUINO_LOG_LOG_LEVEL_TRACE, ARDUINO_LOG_LOG_LEVEL_VERBOSE Note: if you want to
// fully remove all logging code, uncomment #define DISABLE_LOGGING in
// Logging.h
// this will significantly reduce your project size

Log.begin(LOG_LEVEL_VERBOSE, &Serial);
Log.begin(ARDUINO_LOG_LOG_LEVEL_VERBOSE, &Serial);

// Start logging

Expand Down
2 changes: 1 addition & 1 deletion examples/platformio-basic/test/test_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void set_up_logging_captures() {

void setUp(void) {
ArduinoFakeReset();
Log.begin(LOG_LEVEL_VERBOSE, &Serial);
Log.begin(ARDUINO_LOG_LOG_LEVEL_VERBOSE, &Serial);
set_up_logging_captures();
}
void test_int_values() {
Expand Down
16 changes: 8 additions & 8 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ Log KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
LOG_LEVEL_SILENT LITERAL1 Constants
LOG_LEVEL_FATAL LITERAL1 Constants
LOG_LEVEL_ERROR LITERAL1 Constants
LOG_LEVEL_WARNING LITERAL1 Constants
LOG_LEVEL_NOTICE LITERAL1 Constants
LOG_LEVEL_INFO LITERAL1 Constants
LOG_LEVEL_TRACE LITERAL1 Constants
LOG_LEVEL_VERBOSE LITERAL1 Constants
ARDUINO_LOG_LOG_LEVEL_SILENT LITERAL1 Constants
ARDUINO_LOG_LOG_LEVEL_FATAL LITERAL1 Constants
ARDUINO_LOG_LOG_LEVEL_ERROR LITERAL1 Constants
ARDUINO_LOG_LOG_LEVEL_WARNING LITERAL1 Constants
ARDUINO_LOG_LOG_LEVEL_NOTICE LITERAL1 Constants
ARDUINO_LOG_LOG_LEVEL_INFO LITERAL1 Constants
ARDUINO_LOG_LOG_LEVEL_TRACE LITERAL1 Constants
ARDUINO_LOG_LOG_LEVEL_VERBOSE LITERAL1 Constants