Log
For an API reference, see API Reference/Log
The Log module offers an easy way to log messages through USB. See Reading Logs for an introduction on how to read said log messages. The module uses the built-in Arduino Serial.print()
call, with the addition of log-levels and formatting.
Before using the log module, it must be initialized with Log.begin(baudrate)
.
To be able to print floats, the full print support option has to be enabled in the Arduino IDE. To enable this, select Tools -> printf() -> Full, 2.6k, prints floats
.
Example
Log.begin(115200);
Log.setLogLevel(LogLevel::INFO);
// This is printed out
Log.info("Hello World");
Log.warn("This is warning! Be aware!");
Log.error("Something went wrong!");
Log.infof("You can use printf functionality by adding a 'f' at the end of the call: %d\r\n", 2);
Log.errorf("This applies to all the log levels: 0x%X\r\n", 0xABCD);
// This is not printed out
Log.debug("Some low-level debug message");
Log Levels
A log level sets the In computing, verbosity is how much info the program outputs. A program that prints a very detailed output is said to be verbose.verbosity of the logging. The log module only outputs prints that are higher than the currently set log level. These log levels are as follows, ranked from the lowest level to the highest.
- DEBUG
- Detailed debug messages
- INFO
- Informative messages of normal operation (that are not errors). For instance, a "Connected to Broker" message.
- WARN
- Warning messages when something is not an error, but the user should be notified of this. For instance if a HTTP GET call returns an empty body when a non-empty body is expected.
- ERROR
- Error messages which the user must know about. When an error message is printed, something went unexpectedly wrong.
- NONE
- If the log level is none, no messages are printed.
A log level can be set with the log.setLogLevel()
call.
Log.setLogLevel(LogLevel::DEBUG);
Log.setLogLevel(LogLevel::INFO);
Log.setLogLevel(LogLevel::WARN);
Log.setLogLevel(LogLevel::ERROR);
Log.setLogLevel(LogLevel::NONE);
Flash Strings
The log modul supports flash strings with the F(<some string>)
macro. This makes it possible to save RAM usage as the strings will be stored in flash.
Log.info(F("This is a string stored in flash"));