defmt
defmt copied to clipboard
decoder: improve default format
I have updated the default log format to something I consider more sensible. Whether this proposal is the best default or not is of course a very subjective matter.
The main and biggest problem with the current format is the two-line log on the "with location" variant. It introduces a lot of visual noise and it makes it pretty hard to read the logs IMO. It also introduces issues when the user wants to print a multi-line log for whatever reason. In the screenshots below I added an extra line just to emphasize an error, for example. The current version without location is not too bad actually.
The proposed format in this PR introduces the following improvements to the logging experience:
- Single line logs with decent alignment
- Replaces the full path of the log location to just the crate name and the two lowest levels of the file + line number
- I chose to display the two lowest levels only to keep the location short
- I feel like two levels is enough to find out where the log comes from
- Just the filename is useless due to multiple files being called
mod.rs
in a single crate
- Show the crate name in bold for better visibility and contrast
- Color the entire log for warning and error logs for better visibility
- Got rid of the function name in the location
- a lot of times this ends up being something not so useful due to async or closures, e.g.
my_app::____embassy_main_task::{async_fn#0}
- a lot of times this ends up being something not so useful due to async or closures, e.g.
Logs with location before this PR
Logs with location after this PR
Logs without location before this PR
Logs without location after this PR
I hope the proposed format is reasonable. I have no idea why nobody has made an attempt to improve the current one yet, maybe it's not as annoying to others as it is for me. This not only an issue for my own codebases, but generally the default ends up being used as reference material, on blog posts, etc, for example this post on URLO.
Note that the log format continues to be customizable, so if anyone wants to change anything, the option is still there.
Another idea I had was to introduce a new location option that prints just the crate name instead of crate + file name + line number:
I think an option like that would probably be useful for some people as well.