ROS2 Logging

@nburek are there any tutorials, examples, or demos for making use of the new logging features?

1 Like

@nuclearsandwich This doesn’t exist right now but i have opened for our team to track.

is there any process / package to store /rosout into the file system?
e.g) ROS rosout node.

and there are directories under ~/.ros/log/, once we run the ros node there will be directory based on PID. so far it is empty, what this is for? expecting we are able to enable/disable logging to file system under ~/.ros/log/ for each node setting.

@tomoyafujita There are a couple of options right now for logging to a file. There were hooks added in crystal to allow a third-party logger to be hooked up that can handle logging to a file. An implementation using log4cxx was created, but was ultimately not enabled in the release due to some memory safety issues in the library that can cause it to segfault during shutdown ( If you don’t mind that issue you can use the log4cxx logger by compiling rcl_logging_log4cxx and rcl with the set environment variable RCL_LOGGING_IMPLEMENTATION=rcl_logging_log4cxx.

The second option is to configure a log file handler in your launch file. I have not personally looked into it much, so maybe someone else here can provide more detail, but you should now be able to configure your launch files to forward the stdout/stderr from the processes it starts to a log handler class that can be configured to send it to a log file. See the example configuration here:


appreciate for your quick response!

a third-party logger to be hooked up that can handle logging to a file.

actually i already tried to use RCL_LOGGING_IMPLEMENTATION=rcl_logging_sony,
that works just fine, we can use our own implementation.

i was thinking that there is common way(not vendor specific) to log to file? and configurable for each node to do that? of course, we can do that with RCL_LOGGING_IMPLEMENTATION, but i think this is common use-case during debug.

okay i will look into launch_counter


okay launch_counters example is logger setting example for launch.
for launch logger can be configurable launch.logging.launch_config.
actually launch.log is configured in default and store launch log into file system.

what i am looking for is node logger for file system…

The intent had been for rcl_logger_log4cxx to be included by default to solve the common use case. However, the memory safety issue in multithreaded programs was discovered in the last few weeks before the release and there wasn’t time to replace it with something else. There is already done discussions on a new logger implementation that could be used as a default.


thanks for the information to share, really appreciate that.

i mean that dumping info into file system is really common usage as default during development, so i was thinking that it should be generic and enabled as default(but can be configurable), not as in user extension or anything like that.

do you have any information above that?


1 Like

I’ve posted a few PRs that implement a new per-process ROS 2 logger; the main one is at . Any feedback on the proposed implementation and choice of the backend logger is appreciated.


thanks for the PR! i just left my comment on here.

This behavior really hit me by surprise today. I really don’t think this is a good developer/user experience. What’s the best way to solve this? Have the first node that comes online in a process to create a publisher, which then handles publishing all logs to /rosout?

CC’ing @emersonknapp

You start to run into other problems if you just try to have one node handle all the publishing for the entire system. If you’re trying to really tune the performance of a node then it’s even more odd to say that it could unknowingly get assigned an additional publisher if it’s the first to come up. What about if the first Node to come up goes down before the rest of the system?

What should I do when I want to log to syslog?
Because if I understand logging correctly, rcl is logging to all set g_rcl_logging_out_handlers.
I don’t know if g_rcl_logging_ext_lib_enabled could help me or how it could be used at all.

But in our non ROS libraries we also have spdlog and we just use the spdlog sink like that:
auto syslog_sink = std::make_shared<spdlog::sinks::syslog_sink_mt>(logfileName, LOG_PID, LOG_USER);

That would be pretty easy, but spdlog implementation in rcl is fixed to the basic_file_sink_mt.
Customizing rcl_logging_spdlog package is also not an option, as I would need to build all from source…

Yes, rcl is composing multiple output handlers into a single handler that it registers with rcutils (see: and If you just want to disable the spdlog handler then you could use g_rcl_logging_ext_lib_enabled, which gets set based on parameters when you run your ROS application.

If you want to go the route of modifying rcl_logging_spdlog to register a syslog sink instead or in addition to the file sink you could definitely do that. The external logging library is statically linked when rcl is compiled, but I believe that the rcl library is dynamically linked during runtime. That should mean that you only need to recompile rcl_logging_spdlog and rcl and make sure they’re sourced as an overlay to the base ROS install. During development I was recompiling only rcl, rclcpp, and rclpy with the modified loggers and my test application was working correctly. I haven’t tested only recompiling rcl and not the cpp/python client libraries as well, but I think it should work.

Your other option right now if you absolutely don’t want to recompile rcl would be to override the base output handler that rcutils uses for all loggers. All of the individual log out handlers (rosout, stdout, and ext_lib) should all be publicly available in the libraries so you can write your own composition function with your own custom spdlog handler and register it in your application (see how rcl registers it here: The drawback to this approach is that you’ll have to have every ROS application that runs explicitly do this.

If you want to think beyond the Eloquent release, you could always contribute additional functionality to the ROS codebase to make the rcl_logging_spdlog library configurable at runtime or make the external logging library dynamically loaded during runtime instead of during compile. Both of those features were discussed but ultimate cut from initial implementation due to time constraints.


Thanks for the nice explanation!
Really appreciate that.
I need to think about it and look into the options you gave me.

You are right, that was enough for me.
But the overlaying didn’t work for me reliably. So I just build deb packages and installed them…
As this is not a long time solution, I like the idea of having it configurable.
Maybe I can help you out but would need some more information on hoe this should be done.