Arduino Logging framework, easy Logging for microcontrollers using the Arduino framework
- First include the Logging.h header, once the file is included a global object called Logger will be available in every file that includes it
#include <Logger.h>
- Enable the interface you want to use, in this example the Serial interface will be used. once initialized pass it's memory address to the Logger object via begin() method. you may also specify a LoggingLevel, if not specified the default is LoggingLevel::ALL
Serial.begin(9600);
Logger.begin(&Serial, Level::ALL);
- You are now able to log, specify the logging level via template and put a TAG and a MESSAGE as parameters.
Logger.log<Level::I>("My Tag", "Hello world!");
The resulting log will be:
INFO [My Tag] Hello world!
All printable elements with Printer class
are allowed:
Logger.log<Level::D>(F("char *"), "You can print char *");
Logger.log<Level::I>(F("String"), String("Or a String class"));
Logger.log<Level::W>(F("F() or PSTR()"), F("Or a PSTR() macro"));
Logger.log<Level::E>("Hi, i'm a char * tag", F("TAG can also have different types"));
Level | Name | Description |
---|---|---|
OFF | Off | Turns off logging |
F | Fatal | Severe errors that cause premature termination |
E | Error | Other runtime errors or unexpected conditions |
W | Warn | Other runtime situations that are undesirable or unexpected |
I | Info | Interesting runtime events (startup/shutdown) |
D | Debug | Detailed information on the flow through the system |
T | Trace | Flags to check code execution |
ALL | All | Show everything |
Access these levels by using the Level enum
- LOGGER_DISABLE_GLOBAL_INSTANCE: Disable global Logger instance, you need to create your own LoggerClass instances