我在使用 Python 记录器和 rospy 记录器时遇到问题。一开始,一旦 ROS 节点被初始化,Python 记录器就停止记录。我试图通过向记录器添加流处理程序来解决这个问题。现在它只记录 ROS 节点是否初始化。
我在 ROS git 中阅读了有关 rospy 和 python 日志记录冲突的信息。但是似乎没有很好的解决方案来专门使用 python 记录器并且独立于我的代码的 ROS 记录器。
一些模块初始化记录器:
path = "/some_directory/"
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger('logger_name')
# logging file handler for basic log infos
file_handler_info = logging.FileHandler('{}log.log'.format(path))
file_handler_info.setFormatter(formatter)
file_handler_info.setLevel(logging.INFO)
logger.addHandler(file_handler_info)
# logging file handler for critical warnings
file_handler_critical = logging.FileHandler('{}critical.log'.format(path))
file_handler_critical.setFormatter(formatter)
file_handler_critical.setLevel(logging.WARNING)
logger.addHandler(file_handler_critical)
# logging stream handler for console output
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(formatter)
stream_handler.setLevel(logging.DEBUG)
logger.addHandler(stream_handler)
启动 ROS 节点的其他一些模块
logger.info("This message will not be displayed")
rospy.init_node('node_name', anonymous=True)
logger.info("This message will be displayed")
最佳答案
rospy 提供 overriding the default logging configuration :
By default, rospy and other ROS python libraries use $ROS_ROOT/../../etc/ros/python_logging.conf. This file is the standard fileConfig format used by the Python logging module (see https://docs.python.org/library/logging.config.html#configuration-file-format).
You can override the location of this configuration file by setting the ROS_PYTHON_LOG_CONFIG_FILE environment variable.
自定义或创建您自己版本的
python_logging.conf
放在 /opt/ros/YOUR_ROS_DISTRO/etc/ros/
默认情况下。也许加上
streamHandler
就已经足够了到根记录器:[logger_root]
level=DEBUG
handlers=fileHandler,streamHandler
关于python - ROS 记录器禁用 Python 记录器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56668989/