ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
I was having a similar issue to what you described above. This is quite an old question but as it's still the top search result it seems worth answering anyway.
I did a little digging into the rosconsole logging and it seems that it doesn't actually use the default log4cxx file appenders but instead just outputs the logging to stdout where it is piped to a file.
This means normal methods to control stdout work with ROS_INFO etc. On linux an easy way to enable line buffering is to use the command stdbuf before calling roslaunch
stdbuf -o L roslaunch <launchfile>
In code you can also use methods to flush streams/files or set stdout to line buffered
// C++
setvbuf(stdout, NULL, _IOLBF, 4096); // Set line buffering
...
fflush(stdout); // Flush stdout
.
# Python
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1) # Set line buffering
...
sys.stdout.flush() # Flush stdout
Hope that helps someone in the future.