Skip to content

Add {short_file_name} as log format option (backport #541)#543

Merged
ahcorde merged 1 commit intokiltedfrom
mergify/bp/kilted/pr-541
Feb 23, 2026
Merged

Add {short_file_name} as log format option (backport #541)#543
ahcorde merged 1 commit intokiltedfrom
mergify/bp/kilted/pr-541

Conversation

@mergify
Copy link

@mergify mergify bot commented Feb 22, 2026

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 uses strrchr to find the last path separator (/ on POSIX, \ on Windows) and returns everything after it.

Changed files

  • src/logging.c — Added expand_short_file_name() handler and registered the {short_file_name} token in the tokens[] array
  • include/rcutils/logging.h — Added short_file_name to the documented list of available format tokens
  • test/test_logging_console_output_handler.cpp — Added unit tests verifying basename extraction from full paths and passthrough for bare filenames
  • test/test_logging_output_format.py — Added integration test launching with {short_file_name}:{line_number} format and validating output
  • test/test_logging_output_format_short_file_name.txt — Expected output fixture for the integration test

Is this user-facing behavior change?

Yes. Users can now use {short_file_name} in the RCUTILS_CONSOLE_OUTPUT_FORMAT environment 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

* 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
Copy link
Collaborator

fujitatomoya commented Feb 22, 2026

Pulls: #543
Gist: https://gist.githubusercontent.com/fujitatomoya/0d49a8534d24e933005cb2e40e98c7d9/raw/bc17dc3c34c5d709ddbda8a9d9252ba652c90641/ros2.repos
BUILD args: --packages-above-and-dependencies rcutils
TEST args: --packages-above rcutils
ROS Distro: kilted
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/18289

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

@tonynajjar
Copy link
Contributor

tonynajjar commented Feb 22, 2026

@fujitatomoya @ahcorde looks like an unrelated CI failure:

02:17:25     error: downloading 'https://github.com/foxglove/mcap/archive/refs/tags/releases/cpp/v1.4.2.tar.gz' failed
02:17:25           status_code: 22
02:17:25           status_string: "HTTP response code said error"
02:17:25           log:
02:17:25           --- LOG BEGIN ---
02:17:25           Host github.com:443 was resolved.

Can you restart?

@ahcorde ahcorde merged commit 5f92627 into kilted Feb 23, 2026
3 checks passed
@ahcorde ahcorde deleted the mergify/bp/kilted/pr-541 branch February 23, 2026 13:56
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.

3 participants