logging_util.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 
00003 import os
00004 import json
00005 import logging
00006 
00007 
00008 try:
00009     import rospy
00010 except:
00011     pass
00012 
00013 # logging flag
00014 __use_ros_logging = True
00015 
00016 
00017 class Logger(object):
00018     """ logger class
00019     """
00020     info = None
00021     warning = None
00022     degbug = None
00023     critical = None
00024     exception = None
00025 
00026 
00027 def setup_logging(
00028     default_dict={},
00029     default_path='logger_config.json',
00030     default_level=logging.INFO
00031 ):
00032     """ setup logging configuration
00033         default_dict / default_path の両者が設定されている場合、両方のデータを読み込む
00034         データの優先度としては、default_pathに記述されたものが優先度が高い
00035 
00036     :param default_dict: default logging config dict
00037     :param default_path: default logging config path
00038     :param default_level: default log level
00039     """
00040     setup_dict = {}
00041     setup_dict.update(default_dict)
00042 
00043     if os.path.exists(default_path):
00044         with open(default_path, 'rb') as config_file:
00045             setup_dict = json.load(config_file)
00046 
00047     if len(setup_dict.keys()):
00048         logging.config.dictConfig(setup_dict)
00049     else:
00050         FORMAT = '[%(levelname)s] %(message)s @%(filename)s:%(funcName)s:%(lineno)d'
00051         logging.basicConfig(format=FORMAT, level=default_level)
00052 
00053 
00054 def get_logger(name=''):
00055     """ get logger
00056 
00057     :param name: logger name
00058     """
00059     global __use_ros_logging
00060     logger = None
00061     if __use_ros_logging:
00062         logger = Logger()
00063         logger.info = rospy.loginfo
00064         logger.debug = rospy.logdebug
00065         logger.warn = rospy.logwarn
00066         logger.err = rospy.logerr
00067         logger.critical = rospy.logfatal
00068         logger.exception = rospy.logfatal
00069     else:
00070         logger = logging.getLogger(name)
00071 
00072     return logger


rospeex_webaudiomonitor
Author(s): Komei Sugiura
autogenerated on Thu Jun 6 2019 18:53:16