Robotics StackExchange | Archived questions

Overflow ROS logs in ".ros" dir

Hello, I got a problem with overflow ROS logs. For reproducing that I wrote the node:

#! /usr/bin/env python
import rospy
rospy.init_node("SPAM", anonymous=True)
r = rospy.Rate(1000000)
string = "fsafassfaffsadfasf" * 1000
while not rospy.is_shutdown():
   rospy.loginfo(string)
   r.sleep()

And after tests I got the next results:

file list

It turns out, there is we save 250M of logs for each node which however was created. But it is not suitable for me because I have many nodes.

Asked by urpylka on 2018-08-10 12:00:55 UTC

Comments

Answers

rospy uses the python logging module underneath and so all your customizations can just be added to the python logger object directly. To get this level of customization for how the log files are written, you should write your own log handler that would probably inherit from the FileHandler class.

Your code would look something like this:

#!/usr/bin/env python

import rospy
import logging

rospy.init_node('log_test')

logger = logging.getLogger("rosout")

class CustomFileHandler(logging.FileHandler):
    def emit(self, record):
        # handle logging records, I would check the python documentation linked above
    def close(self):
        # close the file

logger.addHandler(CustomFileHandler('path/to/file.log'))

Asked by Jaron on 2021-08-25 09:38:28 UTC

Comments