Skip to content

sys/log: add module for colorized logging#11573

Merged
aabadie merged 3 commits intoRIOT-OS:masterfrom
aabadie:pr/sys/log_color
Sep 9, 2019
Merged

sys/log: add module for colorized logging#11573
aabadie merged 3 commits intoRIOT-OS:masterfrom
aabadie:pr/sys/log_color

Conversation

@aabadie
Copy link
Copy Markdown
Contributor

@aabadie aabadie commented May 24, 2019

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

$ make  BOARD=<your favorite board> -C tests/log_color flash test
$ RIOT_TERMINAL=socat make BOARD=<your favorite board> -C tests/log_color flash term

Issues/PRs references

Based on #11572

@aabadie aabadie added Type: new feature The issue requests / The PR implemements a new feature for RIOT Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels May 24, 2019
@aabadie aabadie requested a review from kaspar030 May 24, 2019 11:46
@aabadie aabadie added the State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet label May 24, 2019
Copy link
Copy Markdown
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?" ;-)).

@@ -0,0 +1,110 @@
/*
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to update this copyright ;-)

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented May 24, 2019

if there would be a separate application to demo/test colorful logs I would care less about the "why?" ;-)

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 :)

@aabadie aabadie force-pushed the pr/sys/log_color branch 7 times, most recently from 857b779 to cfd65b0 Compare May 26, 2019 09:36
@aabadie aabadie added State: waiting for other PR State: The PR requires another PR to be merged first and removed State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet labels May 26, 2019
@kaspar030
Copy link
Copy Markdown
Contributor

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... :)

@miri64
Copy link
Copy Markdown
Member

miri64 commented May 26, 2019

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea for future "feature": make LOG_LEVEL configurable via global variable similar to DEVELHELP.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, what would be the advantage over just setting the define?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ease of use.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make LOG_LEVEL configurable via global variable similar to DEVELHELP

I like the idea :)

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented May 27, 2019

I really have to ask "why?"

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you flushing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And since fflush is not available msp430, this feature is not well supported on this family of platform.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

@aabadie aabadie May 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jcarrano
Copy link
Copy Markdown
Contributor

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.

@aabadie aabadie removed State: waiting for other PR State: The PR requires another PR to be merged first Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR labels Aug 6, 2019
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Aug 27, 2019

Just in case, this is no longer WIP nor waiting for another PR.

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Sep 9, 2019

I'll give my ACK once the dependency is in

@kaspar030, this PR no longer relies on any other PR. I just rebased it on latest master.


USEMODULE += log_color

TEST_ON_CI_WHITELIST += all
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cladmi this is default now, right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be since #11680. @aabadie please remove this line, you can directly squash.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently yes

makefiles/murdock.inc.mk:TEST_ON_CI_WHITELIST ?= all

I'll remove this line then.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@kaspar030 kaspar030 added CI: run tests If set, CI server will run tests on hardware for the labeled PR CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 9, 2019
Copy link
Copy Markdown
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK.

(tested on native and nrf52dk)

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Sep 9, 2019

Thanks for reviewing and ACKing @kaspar030. It's all green, let's merge!

@aabadie aabadie merged commit 60229d1 into RIOT-OS:master Sep 9, 2019
@aabadie aabadie deleted the pr/sys/log_color branch September 9, 2019 19:02
@kb2ma kb2ma added this to the Release 2019.10 milestone Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants