Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consol formating ignores escape sequences #425

Closed
SammyRamone opened this issue Jun 27, 2023 · 4 comments
Closed

Consol formating ignores escape sequences #425

SammyRamone opened this issue Jun 27, 2023 · 4 comments

Comments

@SammyRamone
Copy link
Contributor

The RCUTILS_CONSOLE_OUTPUT_FORMAT environment variable is a very nice way to format the log output of ROS 2 to one's own liking. However, it does not allow using any escape sequences (e.g. \n or any color codes) in it. It think it would be nice if this works, as this would, for example, allow to print different parts of the message in different colors or to structure the information over multiple lines.

Simple example of the issue:

➜ export RCUTILS_CONSOLE_OUTPUT_FORMAT='{name}\n {message}'
➜ echo $RCUTILS_CONSOLE_OUTPUT_FORMAT 
{name}
 {message}
➜ python3 test_log.py
test_node\n Hello World

The '\n' is not interpreted as a new line (ASCII code 10) but as an '' and 'n' (ASCII code 92 and 110). This is the same for all special characters that are set in the environment variable. However, the echo command shows the newline correctly.

If environment variable is empty and the same format is set directly in the code as default format here

rcutils/src/logging.c

Lines 87 to 88 in 025f78f

static const char * g_rcutils_logging_default_output_format =
"[{severity}] [{time}] [{name}]: {message}";

The behavior is correct and the newline is printed.

➜  ws_rcutils python3 test_log.py
test_node
 Hello World

It looks like this issue comes from getting the environment variable.

*env_value = getenv(env_name);

The return of this gives a char array which encodes the '\n' as '' and 'n' characters.

I used zsh, but it also happens with bash. System is Ubuntu 22.04 with ROS rolling.

@fujitatomoya
Copy link
Collaborator

@iuhilnehc-ynos can you take a look at this if you have bandwidth?

@fujitatomoya
Copy link
Collaborator

@SammyRamone it would be appreciated if you can try #426. thanks in advance.

@SammyRamone
Copy link
Contributor Author

@SammyRamone it would be appreciated if you can try #426. thanks in advance.

I don't have time today, but I will try to do it tomorrow.

@fujitatomoya
Copy link
Collaborator

@clalancette i will go ahead to close this issue since this is behavior change, i believe we do not backport this to iron or humble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants