sys/log: add module for colorized logging#11573
Conversation
miri64
left a comment
There was a problem hiding this comment.
Accept for having another example for a log module implementation, I really have to ask "why?". Especially since you want to change hello-world for that (if there would be a separate application to demo/test colorful logs I would care less about the "why?" ;-)).
sys/log/log_color/log_module.h
Outdated
| @@ -0,0 +1,110 @@ | |||
| /* | |||
| * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de> | |||
There was a problem hiding this comment.
You might want to update this copyright ;-)
The updated hello-world is the WIP part of this PR. Having a dedicated log demo/tests is what I want to achieve. I just PR'ed this a bit fast :) |
857b779 to
cfd65b0
Compare
|
LGTM, and it is nicely contained. Works like a charm. I'll give my ACK once the dependency is in. Although I'm more with the "why?" guys... :) |
Though I'm also in the "why?" camp, I can accept the answer "because we can", as long as it is not requiring large overhauls of the code base (which this change does not). |
| TEST_ON_CI_WHITELIST += all | ||
|
|
||
| # Enable debug log level | ||
| CFLAGS += -DLOG_LEVEL=4 |
There was a problem hiding this comment.
Idea for future "feature": make LOG_LEVEL configurable via global variable similar to DEVELHELP.
There was a problem hiding this comment.
Hm, what would be the advantage over just setting the define?
There was a problem hiding this comment.
make LOG_LEVEL configurable via global variable similar to DEVELHELP
I like the idea :)
I think it's a cool/nice feature. But this is not the main argument. In general, having colored logs is helpful to distinguish between the level of messages. With the default logging in RIOT, all log messages looks the same, unless the developer add an extra prefix. |
|
|
||
| #ifdef MODULE_NEWLIB | ||
| /* no fflush on msp430 */ | ||
| fflush(stdout); |
There was a problem hiding this comment.
To force the reset escape code to be printed, otherwise, when one exits the terminal (pyterm or socat or miniterm.py) the last color code still applies and this messes up the host terminal.
There was a problem hiding this comment.
And since fflush is not available msp430, this feature is not well supported on this family of platform.
There was a problem hiding this comment.
Given that the terminal or the riot app can terminate at any moment (and that there is no flush in MSP430), one cannot really count on the RIOT app to reset the terminal state. The robust solution is to have "make term" or pyterm handle this by resetting after exit.
There was a problem hiding this comment.
Except that make term or pyterm are not the only ways to connect to the stdout of a board. If I use miniterm.py /dev/ttyACM0 115200 or minicom or whatever, the terminal is not reset when exiting the tool. I think it's safer to let the call to LOG_XX do this.
|
I think it is important to note that the terms we are using are not very accurate. This (as well as the "noformat") are logging formatters, though currently they implement the logging "sink" too. |
cfd65b0 to
841d298
Compare
|
Just in case, this is no longer WIP nor waiting for another PR. |
841d298 to
3905290
Compare
@kaspar030, this PR no longer relies on any other PR. I just rebased it on latest master. |
tests/log_color/Makefile
Outdated
|
|
||
| USEMODULE += log_color | ||
|
|
||
| TEST_ON_CI_WHITELIST += all |
There was a problem hiding this comment.
Apparently yes
makefiles/murdock.inc.mk:TEST_ON_CI_WHITELIST ?= all
I'll remove this line then.
3905290 to
f6ba779
Compare
kaspar030
left a comment
There was a problem hiding this comment.
ACK.
(tested on native and nrf52dk)
|
Thanks for reviewing and ACKing @kaspar030. It's all green, let's merge! |
Contribution description
This PR adds a custom logging module for adding colors to displayed messages using ANSI escape codes. It can be useful to distinguish the type of messages displayed (ERROR, DEBUG, INFO, etc).
Colors are customizable using CFLAGS.
I had to patch the pyterm script to process the reset sequence correctly when the log message is not terminated by a newline. I haven't found a better solution so far.
Testing procedure
Issues/PRs references
Based on #11572