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

Wired in syslog sink into spdlog #105

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from

Conversation

firesurfer
Copy link

@firesurfer firesurfer commented Oct 10, 2023

This PR wires in an additional syslog sink into the spdlog implementation.

The syslog can be enable via the environment variable:

RCL_LOGGING_SPDLOG_ENABLE_SYSLOG=1

Example output in /var/log/syslog

my_pc my_node[1952055]: [WARN] [1696946734.553229518] [my_node]: my message

It is per default configured to log to the facility: LOG_LOCAL1

By editing /etc/rsyslog.d/50-default.conf and adding the line

We can write the specific log into a seperate file. Alternatively it is possible to redirect the log to a remote server which is useful in enterprise environments.
local1.* -/var/log/local1.log

Additional information

For more background information see the related PR in:
ros2/launch#737

@firesurfer firesurfer changed the title Wired in syslog into spdlog Wired in syslog sink into spdlog Oct 10, 2023
Signed-off-by: Lennart Nachtigall <lennart.nachtigall@sci-mo.de>
@firesurfer
Copy link
Author

@wjwwood and @clalancette sorry for pushing but I would really appreciate some feedback in order to progress :)

@firesurfer
Copy link
Author

@wjwwood and @clalancette sorry to be annyoing but I here am again with a friendly push

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.

@firesurfer sorry to be late to get back to you. i got a couple of comments.
CC: @clalancette @wjwwood

  • does this work on Windows? (I do not think it does...) Windows is one of the Tier 1 platform, and spdlog backend should be working for all of them.
  • i think having environmental variable for each configuration or setting is not really good idea. for that, we already have const char * config_file argument for backend logger initialization. i think that would be the place to put those settings and configuration.

* \param[in] config_file The location of a config file that the external
* logging library should use to configure itself.
* If provided, it must be a null terminated C string.
* If set to NULL or the empty string, the logging library will use defaults.

btw, config_file is not used currently, so maybe we could start, what configuration or setting should be described in config_file for rcl_logging_spdlog?

@firesurfer
Copy link
Author

@fujitatomoya Thanks a lot for your answer. In deed spdlog does not support syslog on Windows. I just took a look at the implementation and it directly uses syslog.h. An alternative on windows could be the Windows eventlog.
Furthermore there are syslog client implementations for windows (quick google search which allows to send syslog entries to a syslog server.

Regarding the config file: My guess would be that only adding new parameters to the config file makes sense in order to not break compatibility. As an alternative we could define for currently implemented parameters that the environment variables will always overwrite their counter pendants in the config file.

@cfveeden
Copy link

cfveeden commented Jan 2, 2024

@fujitatomoya Does ROS2 need to support the same feature set for linux and windows? REP2000 does not seem to say much about that.

So if syslog is a linux only feature of spdlog then adding support for it does not seem to violate any REPs?

Can't we have adding other spdlog features like win_eventlog_sink as a separate PR?

Of course, checking the OS and reporting configuration errors would be required to assist users in configuring their systems properly in this case.

@fujitatomoya
Copy link
Collaborator

Does ROS2 need to support the same feature set for linux and windows?

IMO, basically yes but there are some platform dependent code in ROS 2 core.

Can't we have adding other spdlog features like win_eventlog_sink as a separate PR?

i think we can. i think we can have ifdef platform statement to support syslog for linux and eventlog for windows.

@firesurfer
Copy link
Author

@fujitatomoya and @cfveeden

So let me wrap up the results of the discussion so far:

  1. We want to use the configuration file in order to configure such features instead of using environment variables
  2. I ifdef the syslog support to be only included on linux -> In a seperate PR we can add eventlog for windows

Regarding the configuration file:

At the moment there is only support for passing in the path to a configuration file. There is no definition in which format the configuration file should be.

The documentation actually says:

Note that the format of this file is backend-specific (and is currently unimplemented for the default backend logger of spdlog)

What kind of format would you prefer ? I would suggest using yaml file as they are widely used all over the ROS2 ecosystem. On the other hand this would mean to introduce a new dependency to yaml-cpp.

How should existing parameters be handled ? I already stated my suggestion above:

My guess would be that only adding new parameters to the config file makes sense in order to not break compatibility. As an alternative we could define for currently implemented parameters that the environment variables will always overwrite their counter pendants in the config file.

If I can find some time for that I will try to wire in the config file support in a separate PR.

@cfveeden
Copy link

@firesurfer. I want to make you aware of a similar discussion going on in #103. Can we perhaps coordinate the various additions under #92?

@firesurfer
Copy link
Author

@cfveeden If I understand the discussion in #92 correctly it is unclear when a common solution for the log configuration will be found / worked on. Does this mean no addition to the rcl_logging system can be made until at some point in the future this solution has been found? (Sorry for being a bit provocative there)

The reason I am pushing towards having a syslog functionality is that it is hard at the moment to really get a complete log of an application (without starting to manually collect multiple logfiles from multiple PCs) which can be necessary for debugging certain issues.

Copy link

@130s 130s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the motive, thanks for putting this together. Added a few potentially simple coding questions.

For Windows, there was a recent change announced discourse.ros.org#39502 but I'm not sure how/if that affects this sort of code change.

One question: Like I described one example of logging pipeline answers.ros.org#371667 (of ros1, but I hope the flow of pipeline is the same in ros2), there's a way to configure in OS-system level outside of ROS, in order for logs to be flushed to syslog. In my experience in product dev that sort of flexibility was important.

With this change, if ROS is configured to log onto syslog, would that affect system level configuration for logging? E.g. If my ROS2 application is running as systemd service AND ROS is configured to log to syslog, would I see logs duplicated in syslog?

// explicitly false
return false;
}
if ("1" == env_var_value) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ("1" == env_var_value) {
else if ("1" == env_var_value) {

This if clause and the one previous if are both checking env_var_value, so unless there's a reason for us to check "0" and "1" separately, why don't we combine as a single if-elseif?

try {
std::string env_var_value = rcpputils::get_env_var(env_var_name);

if (env_var_value.empty()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not convert this if clause as else?

@@ -186,6 +236,9 @@ rcl_logging_ret_t rcl_logging_external_initialize(
// the old behavior is to not configure the sink at all, so do nothing
}


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these 3 empty lines addition necessary?

@firesurfer
Copy link
Author

For Windows, there was a recent change announced discourse.ros.org#39502 but I'm not sure how/if that affects this sort of code change.

The discussion points in this thread are still valid. In some way either it should produce an error on windows or fallback to the windows eventlog

With this change, if ROS is configured to log onto syslog, would that affect system level configuration for logging? E.g. If my ROS2 application is running as systemd service AND ROS is configured to log to syslog, would I see logs duplicated in syslog?

I can give you a clear yes and no answer. It depends on the configuration of your local syslog daemon.
If you log from multiple sources to the default syslog then the answer is yes. If you log to a different sink then the answer is probably not. You could also disable console logging for the ROS application in that case.

Regarding the code suggestions -> I think it does not make sense to discuss any of the code until #92 came to a conclusion.

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

Successfully merging this pull request may close these issues.

6 participants