mirror of
https://github.com/CopterExpress/clever-show.git
synced 2026-05-29 08:29:31 +00:00
Logging with ros fix
This commit is contained in:
@@ -16,13 +16,15 @@ parent_dir = os.path.dirname(current_dir)
|
||||
sys.path.insert(0, parent_dir)
|
||||
|
||||
import messaging_lib as messaging
|
||||
import ros_logging
|
||||
|
||||
logging.basicConfig( # TODO all prints as logs
|
||||
level=logging.DEBUG, # INFO
|
||||
format="%(asctime)s [%(name)-7.7s] [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s",
|
||||
handlers=[
|
||||
logging.FileHandler("client_logs.log"),
|
||||
logging.StreamHandler()
|
||||
logging.StreamHandler(),
|
||||
ros_logging.RosHandler(),
|
||||
])
|
||||
|
||||
ConfigOption = collections.namedtuple("ConfigOption", ["section", "option", "value"])
|
||||
|
||||
23
Drone/ros_logging.py
Normal file
23
Drone/ros_logging.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import logging
|
||||
import rospy
|
||||
|
||||
|
||||
class RosHandler(logging.Handler):
|
||||
|
||||
level_map = {
|
||||
logging.DEBUG: rospy.logdebug,
|
||||
logging.INFO: rospy.loginfo,
|
||||
logging.WARNING: rospy.logwarn,
|
||||
logging.ERROR: rospy.logerr,
|
||||
logging.CRITICAL: rospy.logfatal
|
||||
}
|
||||
|
||||
def emit(self, record):
|
||||
try:
|
||||
self.level_map[record.levelno]("%s: %s" % (record.name, record.msg))
|
||||
except KeyError:
|
||||
rospy.logerr("unknown log level %s LOG: %s: %s" % (record.levelno, record.name, record.msg))
|
||||
|
||||
|
||||
def route_logger_to_ros(logger_name):
|
||||
logging.getLogger(logger_name).addHandler(RosHandler())
|
||||
Reference in New Issue
Block a user