goolog
This library provides the no_std-compatible goolog logger and some macros to simplify printing logs.
Usage in embedded / no_std environments
Because this logger is implemented in a no_std environment, it will work with all embedded systems by default.
use *;
Features
std
This feature will:
1. Implement the println
callback using the standard library
2. Implement the on_fatal callback
3. Enable timestamps using chrono
Example
All examples from here on will assume you have the
std
feature active.
use *;
The code above will result in the following output:
# The timestamp (first two blocks) will only be shown when
# the `std` feature is active.
| | | |
But in reality, the log message will be formatted with a color like this:
GREY | GREY | WHITE | * | WHITE
*:
DEBUG -> Blue
ERROR -> Red
INFO -> Green
TRACE -> White
WARN -> Yellow
Quality of life
When printing log lines to the console using these library macros, there are two ways to specify the target:
Specification by macro
This is always possible. Even in combination with the second method described below.
use *;
Specification by constant
For this method, you will only need to specify the target once:
use *;
set_target!;
Customization
Currently, there are two ways to customize your goolog logger:
Changing the logging level
By default, the logger will log at the info
level. To change this, just provide a new log level.
use *;
use Level;
Changing the length of caller names
The default target length is 16 characters. Any given name longer than that will simply be truncated. However, there are two ways to customize this behavior:
1. Change the limit
use *;
2. Remove the limit
To do this set the target_length
to 0
using either of the two ways shown above.
But before you do this, you might consider the drawbacks: If no limit is given, the logger has no way of knowing how much space to leave for the name. Therefore, each log line will 'bend' around the name, which will look something like this:
29.05.2023 | 14:34:33 | Main | INFO | Starting some very important things...
29.05.2023 | 14:34:33 | MySuperAwesomeClient | INFO | Starting...