How to print glog(google log) to console in ros1 noetic in python environment?

asked 2022-10-22 21:31:07 -0500

agua35 gravatar image

I'm working on ros1 noetic and want to print some log on console using glog When I try like below using both rospy.loginfo and glog.info, only rospy.loginfo shows on console The peculiarity is that it works well before the "rospy.init_node" and I could see glog at logfile ~/.ros/log/test_node_2209124_1666490747378.log

How to print glog on console after init_node??

python code

import os
import sys
import glog as log
import rospy

def main(args=None):
  args = args or sys.argv[1:]

  log.setLevel("INFO")
  log.info(f"glog before init_node")
  rospy.loginfo("rospy.loginfo before init_node")

  rospy.init_node('test_node', log_level=rospy.DEBUG, anonymous=True)

  log.info(f"glog after init_node")
  rospy.loginfo("rospy.loginfo after init_node")

  rate = rospy.Rate(1) # 1hz
  while not rospy.is_shutdown():
    rate.sleep()

if__name__ == "__main__":
  main(args=[])

Output console

python3 test.py
I1023 11:05:47.377482 2209124 topics.py:1132] topicmanager initialized
I1023 11:05:47.378640 2209124 test.py:13] glog before init_node
I1023 11:05:47.378696 2209124 test.py:14] rospy.loginfo before init_node
[DEBUG] [1666490747.499155]: init_node, name[/test_node_2209124_1666490747378], pid[2209124]
[DEBUG] [1666490747.499155]: init_node, name[/test_node_2209124_1666490747378], pid[2209124]
[DEBUG] [1666490747.501007]: binding to 0.0.0.0 0
[DEBUG] [1666490747.502680]: bound to 0.0.0.0 34383

[DEBUG] [1666490747.506077]: [/test_node_2209124_1666490747378/get_loggers]: new Service instance

[DEBUG] [1666490747.510686]: [/test_node_2209124_1666490747378/set_logger_level]: new Service instance
[INFO] [1666490747.513658]: rospy.loginfo after init_node
edit retag flag offensive close merge delete