zoukankan      html  css  js  c++  java
  • python配置日志

    logger_file = "%s%s.log" % (LogPath, Setting.box_id)
    print "Will Log into %s"%logger_file
    logger = logging.getLogger(name)        # 获取或初始化logger,不传name,name就是设置的root,默认logging.info/error就是
    logger.setLevel(logging.DEBUG)
    logger_handler = RotatingFileHandler(filename=logger_file, maxBytes=1024 * 1024 * 100, backupCount=10)
    logger_format = logging.Formatter(fmt='[%(asctime)s]-[%(filename)s:%(lineno)s:%(funcName)s]= %(message)s =!',
                                      datefmt='%Y.%m.%d %H:%M:%S')
    logger_handler.setFormatter(logger_format)
    logger.addHandler(logger_handler)
    

    默认logger是root

    root = RootLogger(WARNING)
    
    def getLogger(name=None):
        """
        Return a logger with the specified name, creating it if necessary.
    
        If no name is specified, return the root logger.
        """
        if name:
            return Logger.manager.getLogger(name)
        else:
            return root
    

    默认直接logging.info/error/debug 也是使用的root

    logging.info()
    
    def info(msg, *args, **kwargs):
        """
        Log a message with severity 'INFO' on the root logger.
        """
        if len(root.handlers) == 0:
            basicConfig()
        root.info(msg, *args, **kwargs)
    

    关于logging.Formatter参数格式:

        %(name)s            Name of the logger (logging channel)
        %(levelno)s         Numeric logging level for the message (DEBUG, INFO,
                            WARNING, ERROR, CRITICAL)
        %(levelname)s       Text logging level for the message ("DEBUG", "INFO",
                            "WARNING", "ERROR", "CRITICAL")
        %(pathname)s        Full pathname of the source file where the logging
                            call was issued (if available)
        %(filename)s        Filename portion of pathname
        %(module)s          Module (name portion of filename)
        %(lineno)d          Source line number where the logging call was issued
                            (if available)
        %(funcName)s        Function name
        %(created)f         Time when the LogRecord was created (time.time()
                            return value)
        %(asctime)s         Textual time when the LogRecord was created
        %(msecs)d           Millisecond portion of the creation time
        %(relativeCreated)d Time in milliseconds when the LogRecord was created,
                            relative to the time the logging module was loaded
                            (typically at application startup time)
        %(thread)d          Thread ID (if available)
        %(threadName)s      Thread name (if available)
        %(process)d         Process ID (if available)
        %(message)s         The result of record.getMessage(), computed just as
                            the record is emitted
    
  • 相关阅读:
    对象的方法
    uni-app运行
    flex取值
    阿里矢量库使用
    移动端vue项目模板
    微信分享--转载
    页面流动条
    uni-app打包
    Hibernate~DAO
    EL表达式
  • 原文地址:https://www.cnblogs.com/haiton/p/15752793.html
Copyright © 2011-2022 走看看