Skip to content

Conversation

@alexmaclean6
Copy link

Description

This change adds a new log formatting token option: {severity_with_color}. When used in the log format string, the severity level will be colorized in the log output, but the rest of the line will not be affected. If RCUTILS_COLORIZED_OUTPUT=1, causing the entire line to be colorized, {severity_with_color} behaves the same as {severity}.

Example usage:

[{severity_with_color}] [{name}]: {message} ({function_name}() at {file_name}:{line_number})

Is this user-facing behavior change?

Yes. It allows users to use {severity_with_color} in their log format.

Did you use Generative AI?

No

Additional Information

Signed-off-by: Alex MacLean <[email protected]>
alexmaclean6 and others added 2 commits November 13, 2025 08:03
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
Signed-off-by: Alex MacLean <[email protected]>
@kscottz
Copy link

kscottz commented Nov 20, 2025

@ahcorde waffle team is assigning this to you. Commenting so I see when it gets merged so I can share it with the community.

Copy link
Contributor

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

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

Do you mind to add some documentation on ros2_documentation about how to use this new feature ?

@ahcorde
Copy link
Contributor

ahcorde commented Nov 21, 2025

Pulls: #526
Gist: https://gist.githubusercontent.com/ahcorde/c591acc503548d238ce882328cfc0ff0/raw/6ebf6b072064c5bce038503c864fae1a263e4f3c/ros2.repos
BUILD args: --packages-above-and-dependencies rcutils
TEST args: --packages-above rcutils
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/17570

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@alexmaclean6
Copy link
Author

Do you mind to add some documentation on ros2_documentation about how to use this new feature ?

Happy to. I'll update the documentation on Monday, and create a pull request to ros2_documentation.

@alexmaclean6
Copy link
Author

Added documentation: ros2/ros2_documentation#6045

@alexmaclean6
Copy link
Author

@ahcorde - I'm trying to decipher the build failures that you listed. Are those build infrastructure errors? I don't see compile or test failures in the console output. I only see IO Exceptions for Jenkins and Hudson.

@ahcorde
Copy link
Contributor

ahcorde commented Nov 26, 2025

Pulls: #526
Gist: https://gist.githubusercontent.com/ahcorde/3d9575e6cfd65aaddc2e0a40a30c9d01/raw/6ebf6b072064c5bce038503c864fae1a263e4f3c/ros2.repos
BUILD args: --packages-above-and-dependencies rcutils
TEST args: --packages-above rcutils
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/17617

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Copy link
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

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

@alexmaclean6 are you still working on this? if you are, can you address the CI failures?

@ahcorde
Copy link
Contributor

ahcorde commented Dec 5, 2025

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Signed-off-by: Alejandro Hernández Cordero <[email protected]>
@ahcorde
Copy link
Contributor

ahcorde commented Dec 5, 2025

Pulls: #526
Gist: https://gist.githubusercontent.com/ahcorde/6df1f7dbd8f15748f34bd0005880d29b/raw/6ebf6b072064c5bce038503c864fae1a263e4f3c/ros2.repos
BUILD args: --packages-above-and-dependencies rcutils
TEST args: --packages-above rcutils
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/17700

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

return logging_output->buffer;
}

// Forward declare expand_serverity_with_color to associate it with tokens.
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think this is fine to do that, but not consistent with other handlers that are implemented in here with declaration so that it can get the function pointers to the token table.

Comment on lines +1547 to +1556
// If the severity is 4 characters long, add another space to line it up with the
// 5 character severities.
if (strlen(severity_string) == 4) {
if (rcutils_char_array_strcat(logging_output, " ") != RCUTILS_RET_OK) {
RCUTILS_SAFE_FWRITE_TO_STDERR(rcutils_get_error_string().str);
rcutils_reset_error();
RCUTILS_SAFE_FWRITE_TO_STDERR("\n");
return NULL;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

why we have this padding space only for this handler? i do not think this is consistent behavior for logging format?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ahcorde what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

@fujitatomoya you are more familiar with the logging system. @alexmaclean6 do you mind to address @fujitatomoya comment?

Comment on lines +2 to +3
[\033[0mINFO \033[0m] [name]: Info message (func() at file:42)
[\033[33mWARN \033[0m] [name]: Warn message (func() at file:42)
Copy link
Collaborator

Choose a reason for hiding this comment

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

These need to be without padding space with other console format?

Suggested change
[\033[0mINFO \033[0m] [name]: Info message (func() at file:42)
[\033[33mWARN \033[0m] [name]: Warn message (func() at file:42)
[\033[0mINFO\033[0m] [name]: Info message (func() at file:42)
[\033[33mWARN\033[0m] [name]: Warn message (func() at file:42)

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

Successfully merging this pull request may close these issues.

4 participants