Skip to content

feat: add env variable to configure flushing interval#139

Open
Achllle wants to merge 5 commits intoros2:rollingfrom
Achllle:configurable_flush_period
Open

feat: add env variable to configure flushing interval#139
Achllle wants to merge 5 commits intoros2:rollingfrom
Achllle:configurable_flush_period

Conversation

@Achllle
Copy link

@Achllle Achllle commented Jan 30, 2026

Description

Adds the option to configure the logging interval to file using an environment variable RCL_LOGGING_SPDLOG_FLUSH_PERIOD_SECONDS. Previously this was hardcoded to 5s, which is the default to maintain backwards compatibility. This allows the user to change the interval to a different value, notably including 0, which means unbuffered writes. An example where this is useful is on discourse
Added documentation for the experimental behavior env flag that was not documented yet.

Testing steps

Save the below Dockerfile

FROM ros:rolling

# Install dependencies
RUN apt-get update && apt-get install -y \
    ros-rolling-demo-nodes-cpp \
    multitail \
    git \
    python3-colcon-common-extensions \
    python3-rosdep \
    && rm -rf /var/lib/apt/lists/*

# Create workspace
WORKDIR /ros2_ws

# Clone the fork with configurable flush period
RUN git clone --branch configurable_flush_period \
    https://github.com/Achllle/rcl_logging.git src/rcl_logging

RUN apt-get update && rosdep install --from-paths src --ignore-src -r -y

# Build rcl_logging overlay
RUN . /opt/ros/rolling/setup.sh && \
    colcon build --packages-up-to rcl_logging_spdlog

# Create launch file
RUN mkdir -p /ros2_ws/launch
COPY <<EOF /ros2_ws/launch/demo.launch.py
from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='demo_nodes_cpp',
            executable='talker',
            name='my_talker_node',
            output='screen',
            emulate_tty=True,
        ),
        Node(
            package='demo_nodes_cpp',
            executable='listener',
            name='my_listener_node',
            output='screen',
            emulate_tty=True,
        )
    ])
EOF

# Create entrypoint script
COPY <<EOF /ros2_ws/entrypoint.sh
#!/bin/bash
set -e

# Source the overlay
source /ros2_ws/install/setup.bash

# Set log directory
export ROS_LOG_DIR=\${ROS_LOG_DIR:-/tmp/ros_logs}
mkdir -p "\$ROS_LOG_DIR"

# Print configuration
echo "=== RCL Logging Demo ==="
echo "RCL_LOGGING_SPDLOG_FLUSH_PERIOD_SECONDS=\${RCL_LOGGING_SPDLOG_FLUSH_PERIOD_SECONDS:-not set (default 5s)}"
echo "ROS_LOG_DIR=\$ROS_LOG_DIR"
echo "========================"
echo ""

# Launch nodes in background, redirect output to /dev/null
ros2 launch /ros2_ws/launch/demo.launch.py > /dev/null 2>&1 &
LAUNCH_PID=\$!

# Wait for log files to appear
sleep 2

# Use multitail to follow all log files in ROS_LOG_DIR
exec multitail -Q 1 "\$ROS_LOG_DIR/*.log"
EOF

RUN chmod +x /ros2_ws/entrypoint.sh

# Default environment
ENV ROS_LOG_DIR=/tmp/ros_logs

ENTRYPOINT ["/ros2_ws/entrypoint.sh"]

then docker build -t rcl-logging-demo .

  • default behavior: docker run -it --rm rcl-logging-demo:latest: logs are buffered for 5s
  • try other interval: docker run -it --rm -e RCL_LOGGING_SPDLOG_FLUSH_PERIOD_SECONDS=0 rcl-logging-demo:latest: logs are unbuffered

Did you use Generative AI?

yes, Claude Opus 4.5

Additional Information

relevant issue about config file: #92

Signed-off-by: Achllle <achille.verheye@gmail.com>
@Achllle Achllle force-pushed the configurable_flush_period branch from cc98166 to c256b1f Compare January 30, 2026 06:34
@ahcorde ahcorde requested a review from fujitatomoya February 5, 2026 11:34
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.

There have been several issues and discussions around configuring the logging implementation. The original plan (see #92) was to use the config file argument as a generic ROS 2 logging configuration layer that would translate settings to the specific backend implementation. However, that work was never implemented, and as far as I can tell, no one is actively working on it. Given that, I think this spdlog-specific configuration via an environment variable is a practical and useful addition for ROS 2 applications that depend on the spdlog backend today.

CC: @wjwwood @ahcorde @mjcarroll

Signed-off-by: Achllle <achille.verheye@gmail.com>
Signed-off-by: Achllle <achille.verheye@gmail.com>
Signed-off-by: Achllle <achille.verheye@gmail.com>
@fujitatomoya
Copy link
Collaborator

@Achllle thanks for the fix. i am good to go with this, but i would like to have another approval from other maintainers before merge. i will go ahead to start the CI.

@fujitatomoya
Copy link
Collaborator

Pulls: #139
Gist: https://gist.githubusercontent.com/fujitatomoya/d6865b43fee22387bf04ec21ac5fb6d8/raw/f7bff7e897e32b5cc7f1541ee14bcb4b5f42ffae/ros2.repos
BUILD args: --packages-above-and-dependencies rcl_logging_spdlog
TEST args: --packages-above rcl_logging_spdlog
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/18146

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

@ahcorde
Copy link
Contributor

ahcorde commented Feb 9, 2026

Pulls: #139
Gist: https://gist.githubusercontent.com/ahcorde/e998924c08ca7fdd03e851c12795665b/raw/f7bff7e897e32b5cc7f1541ee14bcb4b5f42ffae/ros2.repos
BUILD args: --packages-above-and-dependencies rcl_logging_spdlog
TEST args: --packages-above rcl_logging_spdlog
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/18151

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

@wjwwood
Copy link
Member

wjwwood commented Feb 10, 2026

There have been several issues and discussions around configuring the logging implementation. The original plan (see #92) was to use the config file argument as a generic ROS 2 logging configuration layer that would translate settings to the specific backend implementation. However, that work was never implemented, and as far as I can tell, no one is actively working on it. Given that, I think this spdlog-specific configuration via an environment variable is a practical and useful addition for ROS 2 applications that depend on the spdlog backend today.

CC: @wjwwood @ahcorde @mjcarroll

Works for me. While I would like to see us have the logging config, I think I would be more concerned with a larger feature revolving around logging than this. Pragmatically, this is a reasonable compromise.

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.

…flush period values

The previous implementation rejected non-digit characters with a single
generic message, causing HasSubstr("not a valid integer") and
HasSubstr("trailing characters") test assertions to fail.

Replace the character loop with std::stoi(..., &pos):
- fully non-numeric input (e.g. "abc")  -> "... is not a valid integer"
- trailing characters (e.g. "5abc")     -> "... trailing characters after integer"
- negative value (e.g. "-1")            -> "... value must be non-negative"
- out-of-range                           -> "... value is out of range"

Fixes rcl_logging_spdlog LoggingTest.init_with_invalid_flush_period_non_integer
and LoggingTest.init_with_invalid_flush_period_trailing_chars.

Signed-off-by: Ubuntu <achille.verheye@gmail.com>
@Achllle
Copy link
Author

Achllle commented Mar 3, 2026

Apologies, that's on me - the failures went unnoticed because I saw linter and copyright test failures which I knew were related to building without installing. Addressed in f2efa39.

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.

lgtm with green CI.

@fujitatomoya
Copy link
Collaborator

Pulls: #139
Gist: https://gist.githubusercontent.com/fujitatomoya/08079122c6f6beb237318946fdc27af2/raw/f7bff7e897e32b5cc7f1541ee14bcb4b5f42ffae/ros2.repos
BUILD args: --packages-above-and-dependencies rcl_logging_spdlog
TEST args: --packages-above rcl_logging_spdlog
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/18359

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

@fujitatomoya
Copy link
Collaborator

@Achllle can you take a look at ros2/ros2_documentation#6276?

@Achllle
Copy link
Author

Achllle commented Mar 4, 2026

Thanks for updating the docs - I should have realized to do so.

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