ros / rosconsole

17 stars 61 forks source link

write errors / warnings also to stdout (beside stderr) #41

Closed berry0511 closed 4 years ago

berry0511 commented 4 years ago

I'm wondering why ROS_ERROR cannot be logged to log file? In my case, I don't have an monitor, so all thing should be logged. But all nodes ERR msgs are logged to rosout.log instead of indepandent node's log. it's hard to search.

dirk-thomas commented 4 years ago

(I also updated the ticket title since the patch is not about flushing but actually printing the message to multiple streams.)

dirk-thomas commented 4 years ago

Since it is clearly undesired that the same message is printed to both streams (just considering the trivial use case of a node being run in a console) I will go ahead and close this ticket for now.

Please feel free to comment on the close ticket to discuss any alternative approaches.

berry0511 commented 4 years ago

Okay, I will try to find another way :)

jonathankehler commented 3 years ago

In light of this I'd like to know how people are approaching the following problem: In both roscpp and rospy if a node encounters an exception in the main loop the stacktrace/backtrace should go to stderr. When running the node with roslaunch these are visible on the console. But how would one direct the stderr of a ROS node to a log file (stderr that is NOT in the form of ros error logs).

For example in rospy if I raise an AssertionError in the mainloop of a node I can see that on stderr of roslaunch BUT it never gets into any log files.

It seems like ROS logging was not designed to handle this (though I'm not sure why) and if thats the case how people are working around this issue.

acarrillo commented 3 years ago

I think this is still an active issue. I am trying to find if there is perhaps a proper place to vet out the right solution with OSRF maintainers...maybe a ROS Discourse post?

sdo91 commented 2 years ago

@dirk-thomas , I understand why you say it doesn't make sense to log stderr to the stdout file.

however, as this question states, the <node_name>-stderr.log files are not being created: https://answers.ros.org/question/251206/ros-log-named-and-stderr/ Instead, all stderr messages from all nodes are being dumped into a single rosout.log file I have observed this is ROS kinetic, melodic, and noetic.

Do you know then what is the "correct" way of viewing the stderr messages of a given node?

AleksandrBon commented 2 years ago

Hi,

looks like there is a contradiction between what is stated in ROS documentation and what it really does. If @dirk-thomas needs some more solid reason to allow forwarding of error/warning messages to node log files. As stated in rosconsole description file rosconsole.config can be redefined to allow to configure severity level for each node separately. Then each node also can be configured to forward log data to its own log file with output=log statement. And because severity levels are nested by definition, that means all messages with severity >= than specified in configuration for node should be forwarded to node log file. And this is expected behavior, otherwise this breaks nesting ideology.

@berry0511 if you still want to have possibility to write all messages to log files there is some ugly solution. As ROS uses log4j logger, you can define rosconsole_your_node.config to add log4j appender for your node with all properties that you need. Look example at log4j config example.

log4j.logger.ros.your_node=INFO,fout
log4j.appender.fout=org.apache.log4j.FileAppender
log4j.appender.fout.File=logfile.log
log4j.appender.fout.layout=org.apache.log4j.PatternLayout
log4j.appender.fout.layout.ConversionPattern=%p %d{ISO8601} %r %c [%t] %m%n

And with this you can configure rolling file logger too. And you need to set for your node in launch file output=screen. Yes, errors and warnings still will be published to rosout as it was, but you will have log file all severity levels in one. The limitation with that way is that to this file will be printed only log messages created with the ROS_DEBUG, ROS_INFO etc. macros, and not with standard printf or cout and belonging only to this node. And if yournode has calls to some other ROS library functions that also have ROS... log calls inside, this messages also will not be printed to log.

Another solution could be to implement your own logger based on boost.log for example. But this is another story.

dirk-thomas commented 2 years ago

@sdo91 @AleksandrBon I am not the maintainer of this repository anymore.

douglewis22 commented 1 year ago

Thank you for the log4j work around @AleksandrBon !
I agree that the ROS documentation does not agree with the ROS implementation and this should be corrected! It sounds like a number of users have a use case where they want logging messages in a node log file and not just dumped into rosout.