Skip to content
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

Logging to journald? #16

Open
mgrrx opened this issue Sep 5, 2018 · 3 comments
Open

Logging to journald? #16

mgrrx opened this issue Sep 5, 2018 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@mgrrx
Copy link
Contributor

mgrrx commented Sep 5, 2018

We are currently looking into rosconsole to find a way to directly write to the system journal using sd_journal_send. One could of course simply use the builtin feature of log4cxx to log to syslog and use the compatibility layer of systemd for syslog, but this comes with one big limitation: Syslog uses the program_invocation_short_name to identify the sender, which is not the perfect way to identify a program in a ROS context, especially when one has two instances of the same binary with different node names.

The big benefit of systemd's journal is that one can set the SYSLOG_IDENTIFIER. The obvious idea is to set this value to the node name which makes it really convenient to read the journal and I have code ready that does exactly this. Sadly this can't be done given the current dependency structure since the node name is only available in ros/this_node.h in roscpp which is a downstream package.

...

void SystemJournalAppender::append(const log4cxx::spi::LoggingEventPtr& event,
                                   log4cxx::helpers::Pool&)
{
  const log4cxx::spi::LocationInfo& location_info = event->getLocationInformation();
  ::sd_journal_send(
    "MESSAGE=%s", event->getMessage().c_str(),
    "PRIORITY=%i", event->getLevel()->getSyslogEquivalent(),
    "CODE_FILE=%s", location_info.getFileName(),
    "CODE_LINE=%i", location_info.getLineNumber(),
    "CODE_FUNC=%s", location_info.getMethodName().c_str(),
    "SYSLOG_IDENTIFIER=%s", ros::this_node::getName().c_str(),
    NULL);
}

I'm opening this ticket to ask for advice on how to continue here. I've two suggestions:

  1. Add the node name as an argument to ROSCONSOLE_AUTOINIT and ros::console::initialize. This internally sets a global variable which can be used in the log appender.
  2. Use pluginlib to load additional plugins during runtime, just before the log4cxx configuration is parsed log4cxx::PropertyConfigurator::configure(config_file). This requires some additional work to make pluginlib use console_bridge instead of rosconsole (Depend on libconsole-bridge-dev instead of rosconsole? pluginlib#81). The advantage would be that it allows others to implement their own custom log appenders.

I personally prefer solution 2 but this would of course be a significant change.

@mgrrx
Copy link
Contributor Author

mgrrx commented Sep 22, 2018

I started implementing what is needed for solution 2:

  1. https://github.com/magazino/rosconsole/tree/log4cxx-appender registers the ROSConsoleStdioAppender class as a log4cxx appender which can be configured using the log4cxx config file. This would allow me to disable the print to stdout/stderr.
  2. https://github.com/magazino/pluginlib/tree/kinetic-console-bridge (not yet ported to melodic) replaces rosconsole with console bridge. This is required to use pluginlib in rosconsole.
  3. https://github.com/magazino/rosconsole/tree/custom-appenders adds pluginlib as a dependency and loads all available ronsconsole log4cxx plugins right before the config file is parsed. This sets the basis to write custom log appenders.
  4. https://github.com/magazino/systemd_ros adds a custom log4cxx appender which writes to the journal.

I don't know where to call REGISTER_ROSCONSOLE_BRIDGE and add rosconsole_bridge to forward the console bridge output of pluginlib. I was wondering why rosconsole_bridge is a separate package at all and not part of rosconsole.

Would be great to get some feedback on my ideas and how to move forward.

@flixr
Copy link
Contributor

flixr commented Jun 7, 2020

Any updates here? This would be very useful!

@dirk-thomas dirk-thomas added the enhancement New feature or request label Jul 13, 2020
@dirk-thomas dirk-thomas added this to the untargeted milestone Jul 13, 2020
@Hugal31
Copy link

Hugal31 commented Jul 29, 2021

This would be very nice!
As a backup solution, wouldn't it be possible to create a node that subscribes to /rosout and copy the logs to Journald?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants