-
Notifications
You must be signed in to change notification settings - Fork 113
Adds {severity_with_color} as a log format option. #526
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
Open
alexmaclean6
wants to merge
6
commits into
ros2:rolling
Choose a base branch
from
alexmaclean6:severity_with_color
base: rolling
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b7a4469
Adds {severity_with_color} as a log format option.
7eca440
Fix linting errors.
a728158
Apply suggestions from code review
alexmaclean6 8674a60
Add documentation about to logging.h.
2aaaf97
Update src/logging.c
ahcorde 577636d
review feedback
ahcorde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright 2025 Open Source Robotics Foundation, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include <iostream> | ||
|
|
||
| #include "rcutils/error_handling.h" | ||
| #include "rcutils/logging.h" | ||
| #include "rcutils/types/rcutils_ret.h" | ||
|
|
||
| int main(int, char **) | ||
| { | ||
| rcutils_ret_t ret = rcutils_logging_initialize(); | ||
| if (ret != RCUTILS_RET_OK) { | ||
| std::cerr << "error initializing logging: " << rcutils_get_error_string().str << std::endl; | ||
| return -1; | ||
| } | ||
|
|
||
| rcutils_ret_t status = rcutils_logging_set_logger_level("name", RCUTILS_LOG_SEVERITY_DEBUG); | ||
| if (status != RCUTILS_RET_OK) { | ||
| std::cerr << "error setting logger level: " << rcutils_get_error_string().str << std::endl; | ||
| return -1; | ||
| } | ||
|
|
||
| // Log at all 5 severities to check the colorized severity in the log output. | ||
| rcutils_log_location_t location = {"func", "file", 42u}; | ||
| rcutils_log(&location, RCUTILS_LOG_SEVERITY_DEBUG, "name", "Debug message"); | ||
| rcutils_log(&location, RCUTILS_LOG_SEVERITY_INFO, "name", "Info message"); | ||
| rcutils_log(&location, RCUTILS_LOG_SEVERITY_WARN, "name", "Warn message"); | ||
| rcutils_log(&location, RCUTILS_LOG_SEVERITY_ERROR, "name", "Error message"); | ||
| rcutils_log(&location, RCUTILS_LOG_SEVERITY_FATAL, "name", "Fatal message"); | ||
|
|
||
| std::cout.flush(); | ||
|
|
||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # Copyright 2025 Open Source Robotics Foundation, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import os | ||
| import unittest | ||
|
|
||
| from launch import LaunchDescription | ||
| from launch.actions import ExecuteProcess | ||
| from launch.actions import SetEnvironmentVariable | ||
|
|
||
| import launch_testing | ||
| import launch_testing.actions | ||
| import launch_testing.asserts | ||
| import launch_testing.markers | ||
|
|
||
|
|
||
| @launch_testing.markers.keep_alive | ||
| def generate_test_description(): | ||
| test_process_name = 'test_logging_severity_with_color' | ||
| launch_description = LaunchDescription() | ||
| # Set the output format to a "verbose" format that is expected by the executable output | ||
| launch_description.add_action( | ||
| SetEnvironmentVariable( | ||
| name='RCUTILS_CONSOLE_OUTPUT_FORMAT', | ||
| value='[{severity_with_color}] [{name}]: {message} ' | ||
| '({function_name}() at {file_name}:{line_number})' | ||
| ) | ||
| ) | ||
| launch_description.add_action( | ||
| SetEnvironmentVariable( | ||
| name='RCUTILS_COLORIZED_OUTPUT', | ||
| value='0' | ||
| ) | ||
| ) | ||
| executable = os.path.join(os.getcwd(), test_process_name) | ||
| if os.name == 'nt': | ||
| executable += '.exe' | ||
| process_name = test_process_name | ||
| launch_description.add_action( | ||
| ExecuteProcess(cmd=[executable], name=process_name, output='screen') | ||
| ) | ||
|
|
||
| launch_description.add_action( | ||
| launch_testing.actions.ReadyToTest() | ||
| ) | ||
| return launch_description, {'process_name': process_name} | ||
|
|
||
|
|
||
| class TestLoggingSeverityWithColor(unittest.TestCase): | ||
|
|
||
| def test_wait_for_shutdown(self, proc_info, proc_output, process_name): | ||
| """Wait for the process to complete so the log messages will be available to inspect.""" | ||
| proc_info.assertWaitForShutdown(process=process_name, timeout=10) | ||
|
|
||
|
|
||
| @launch_testing.post_shutdown_test() | ||
| class TestLoggingSeverityWithColorAfterShutdown(unittest.TestCase): | ||
|
|
||
| def test_logging_output(self, proc_output, process_name): | ||
| """Test executable output against expectation.""" | ||
| launch_testing.asserts.assertInStderr( | ||
| proc_output, | ||
| expected_output=launch_testing.tools.expected_output_from_file( | ||
| path=os.path.join(os.path.dirname(__file__), process_name), | ||
| encoding='unicode_escape' | ||
| ), | ||
| process=process_name, | ||
| strip_ansi_escape_sequences=False | ||
| ) | ||
|
|
||
| def test_processes_exit_codes(self, proc_info): | ||
| """Test that all executables finished cleanly.""" | ||
| launch_testing.asserts.assertExitCodes(proc_info) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [\033[32mDEBUG\033[0m] [name]: Debug 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) | ||
| [\033[31mERROR\033[0m] [name]: Error message (func() at file:42) | ||
| [\033[31mFATAL\033[0m] [name]: Fatal message (func() at file:42) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.