Add {short_file_name} as log format option (backport #541)#543
Open
mergify[bot] wants to merge 1 commit intokiltedfrom
Open
Add {short_file_name} as log format option (backport #541)#543mergify[bot] wants to merge 1 commit intokiltedfrom
mergify[bot] wants to merge 1 commit intokiltedfrom
Conversation
* Add short_file_name Signed-off-by: Tony Najjar <tony.najjar@dexory.com> * PR comments Signed-off-by: Tony Najjar <tony.najjar@dexory.com> * fix windows set_env Signed-off-by: Tony Najjar <tony.najjar@dexory.com> --------- Signed-off-by: Tony Najjar <tony.najjar@dexory.com> (cherry picked from commit 0575342)
fujitatomoya
approved these changes
Feb 22, 2026
Collaborator
|
Pulls: #543 |
Contributor
|
@fujitatomoya looks like an unrelated CI failure: Can you restart? |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Add a new
{short_file_name}format token to the rcutils logging system that outputs only the basename of the source file (e.g.,my_node.cpp) instead of the full path (e.g.,/opt/ros_ws/src/my_package/src/my_node.cpp).The existing
{file_name}token continues to output the full path as before. The new token usesstrrchrto find the last path separator (/on POSIX,\on Windows) and returns everything after it.Changed files
src/logging.c— Addedexpand_short_file_name()handler and registered the{short_file_name}token in thetokens[]arrayinclude/rcutils/logging.h— Addedshort_file_nameto the documented list of available format tokenstest/test_logging_console_output_handler.cpp— Added unit tests verifying basename extraction from full paths and passthrough for bare filenamestest/test_logging_output_format.py— Added integration test launching with{short_file_name}:{line_number}format and validating outputtest/test_logging_output_format_short_file_name.txt— Expected output fixture for the integration testIs this user-facing behavior change?
Yes. Users can now use
{short_file_name}in theRCUTILS_CONSOLE_OUTPUT_FORMATenvironment variable to display only the source file basename in log output, reducing log line length and improving readability.Did you use Generative AI?
Yes — GitHub Copilot (Claude Opus 4.6)
Additional Information
/) and Windows (\) path separators via#ifdef _WIN32. Tested on Ubuntu Linux but I don't have a way to test on Windows.rcutils_log_location_tstruct — the basename is extracted at format-expansion timeThis is an automatic backport of pull request Add {short_file_name} as log format option #541 done by Mergify.