当前位置: 首页>>代码示例>>Python>>正文


Python handlers.RotatingFileHandler方法代码示例

本文整理汇总了Python中logging.handlers.RotatingFileHandler方法的典型用法代码示例。如果您正苦于以下问题:Python handlers.RotatingFileHandler方法的具体用法?Python handlers.RotatingFileHandler怎么用?Python handlers.RotatingFileHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在logging.handlers的用法示例。


在下文中一共展示了handlers.RotatingFileHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup_logging

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import RotatingFileHandler [as 别名]
def setup_logging(log_dir):
    log_file_format = "[%(levelname)s] - %(asctime)s - %(name)s - : %(message)s in %(pathname)s:%(lineno)d"
    log_console_format = "[%(levelname)s]: %(message)s"

    # Main logger
    main_logger = logging.getLogger()
    main_logger.setLevel(logging.INFO)

    console_handler = logging.StreamHandler()
    console_handler.setLevel(logging.INFO)
    console_handler.setFormatter(Formatter(log_console_format))

    exp_file_handler = RotatingFileHandler('{}exp_debug.log'.format(log_dir), maxBytes=10**6, backupCount=5)
    exp_file_handler.setLevel(logging.DEBUG)
    exp_file_handler.setFormatter(Formatter(log_file_format))

    exp_errors_file_handler = RotatingFileHandler('{}exp_error.log'.format(log_dir), maxBytes=10**6, backupCount=5)
    exp_errors_file_handler.setLevel(logging.WARNING)
    exp_errors_file_handler.setFormatter(Formatter(log_file_format))

    main_logger.addHandler(console_handler)
    main_logger.addHandler(exp_file_handler)
    main_logger.addHandler(exp_errors_file_handler) 
开发者ID:moemen95,项目名称:Pytorch-Project-Template,代码行数:25,代码来源:config.py

示例2: create_access_log

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import RotatingFileHandler [as 别名]
def create_access_log(log_file, log_name, formatter):
    '''
    One-time configuration for the web server's access log.
    '''
    log_file = _absolute_log_file(log_file, DEFAULT_ACCESS_LOG)
    logging.debug("access log: %s", log_file)

    access_log = logging.getLogger(log_name)
    access_log.propagate = False
    access_log.setLevel(logging.INFO)
    try:
        file_handler = RotatingFileHandler(log_file, maxBytes=50000, backupCount=2)
    except IOError:
        if log_file == DEFAULT_ACCESS_LOG:
            raise
        file_handler = RotatingFileHandler(DEFAULT_ACCESS_LOG, maxBytes=50000, backupCount=2)
        log_file = ""

    file_handler.setFormatter(formatter)
    access_log.addHandler(file_handler)
    return access_log, \
           "" if _absolute_log_file(log_file, DEFAULT_ACCESS_LOG) == DEFAULT_ACCESS_LOG else log_file


# Enable logging of smtp lib debug output 
开发者ID:janeczku,项目名称:calibre-web,代码行数:27,代码来源:logger.py

示例3: log_setup

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import RotatingFileHandler [as 别名]
def log_setup(loglevel):
    tests_path = os.path.dirname(os.path.abspath(__file__))
    log_handler = RotatingFileHandler(tests_path + '/log/probeim.log', maxBytes=1048576, backupCount=5)

    formatter = logging.Formatter('%(asctime)s - %(levelname)s: %(message)s -- %(filename)s::%(funcName)s'
                                  ' line     %(lineno)d', '%b %d %H:%M:%S')
    formatter.converter = time.gmtime
    log_handler.setFormatter(formatter)
    logger = logging.getLogger()
    logger.addHandler(log_handler)

    if loglevel == 'ERROR':
        lvl = 40
    elif loglevel == 'WARNING':
        lvl = 30
    elif loglevel == 'INFO':
        lvl = 20
    elif loglevel == 'DEBUG':
        lvl = 10
    else:
        lvl = 30

    logger.setLevel(lvl) 
开发者ID:grycap,项目名称:im,代码行数:25,代码来源:probeim.py

示例4: initlogger

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import RotatingFileHandler [as 别名]
def initlogger(self, level, name):
        """
        初始化logger
        """
        cwd = os.getcwd()
        formatter = logging.Formatter(self.LOG_FORMAT)
        logger = logging.getLogger(name)
        logger.setLevel(level)
        fh = RotatingFileHandler(os.path.join(cwd, 'logs', name),
                                 maxBytes=10 * 1024 * 1024,
                                 backupCount=5)
        fh.setFormatter(formatter)
        fh.setLevel(level)
        logger.addHandler(fh)
        if level is not logging.DEBUG:
            ch = StreamHandler()
            ch.setFormatter(formatter)
            ch.setLevel(level)
            logger.addHandler(ch)
        return logger 
开发者ID:tianjyan,项目名称:Qzone_Photo,代码行数:22,代码来源:logger.py

示例5: configure_logging

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import RotatingFileHandler [as 别名]
def configure_logging():
    namespace = {}
    namespace['base_dir'] = os.path.abspath(os.path.dirname(__file__))
    namespace['logfile'] = os.path.join(namespace['base_dir'], "flask-example.log")
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.DEBUG)
    rotating_file_handler = RotatingFileHandler(namespace['logfile'], maxBytes=10000, backupCount=20)
    rotating_file_handler.setLevel(logging.DEBUG)
    console_stream_handler = logging.StreamHandler()
    console_stream_handler.setLevel(logging.DEBUG if namespace.get('debug') else logging.INFO)
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    console_stream_handler.setFormatter(formatter)
    rotating_file_handler.setFormatter(formatter)
    logger.addHandler(console_stream_handler)
    logger.addHandler(rotating_file_handler)
    return logger, rotating_file_handler, console_stream_handler 
开发者ID:xBrite,项目名称:flyingcloud,代码行数:18,代码来源:app.py

示例6: __init__

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import RotatingFileHandler [as 别名]
def __init__(self, file):
        Singleton.__init__(self)
        self.eclogger = logging.getLogger(file)
        self.eclogger.setLevel(level=logging.DEBUG)
        if not self.eclogger.handlers:
            self.rotate_handler = RotatingFileHandler("FECA.log", maxBytes=1024 * 1024, backupCount=5)
            self.rotate_handler.setLevel(level=logging.DEBUG)
            DATE_FORMAT = "%m/%d/%Y %H:%M:%S %p"
            formatter = logging.Formatter(fmt='%(asctime)s(File:%(name)s,Line:%(lineno)d, %(funcName)s) - %(levelname)s - %(message)s', datefmt=DATE_FORMAT)

            self.rotate_handler.setFormatter(formatter)
            self.eclogger.addHandler(self.rotate_handler)

    # def __deepcopy__(self, memodict={}):
    #     copy_object = type(self)("new_FECA.log")
    #     copy_object.rotate_handler = copy.deepcopy(self.rotate_handler, memodict)
    #     copy_object.eclogger = copy.deepcopy(self.eclogger, memodict)
        # return copy_object 
开发者ID:salan668,项目名称:FAE,代码行数:20,代码来源:EcLog.py

示例7: set_logger

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import RotatingFileHandler [as 别名]
def set_logger(level):
    #log related
    work_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
    log_dir = work_dir + '/data/ossftp/'
    mkdir_p(log_dir)
    LOGFILE = log_dir + "ossftp.log"
    MAXLOGSIZE = 10*1024*1024 #Bytes
    BACKUPCOUNT = 30
    FORMAT = \
        "%(asctime)s %(levelname)-8s[%(filename)s:%(lineno)d(%(funcName)s)] %(message)s"
    handler = RotatingFileHandler(LOGFILE,
                mode='w',
                maxBytes=MAXLOGSIZE,
                backupCount=BACKUPCOUNT)
    formatter = logging.Formatter(FORMAT)
    handler.setFormatter(formatter)
    logger = logging.getLogger()
    logger.setLevel(level)
    logger.addHandler(handler) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:21,代码来源:ftpserver.py

示例8: init_log

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import RotatingFileHandler [as 别名]
def init_log():
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    file_handler = RotatingFileHandler(os.path.join(BASE_DIR, 'log', 'agent.log'),
                                       maxBytes=1024 * 1024 * 50,
                                       backupCount=10)
    file_handler.setLevel(logging.INFO)
    file_handler.setFormatter(formatter)
    logger.addHandler(file_handler)

    stream_handler = logging.StreamHandler()
    stream_handler.setLevel(logging.INFO)
    stream_handler.setFormatter(formatter)
    logger.addHandler(stream_handler)
    return logger 
开发者ID:510908220,项目名称:heartbeats,代码行数:18,代码来源:agent.py

示例9: config_logger

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import RotatingFileHandler [as 别名]
def config_logger(logger):
    logger_level = cfg.LOGGING_LEVEL_CONSOLE

    if cfg.LOGGING_FILE is not None:
        logfile_handler = RotatingFileHandler(
            cfg.LOGGING_FILE, mode='a',
            maxBytes=cfg.LOGGING_FILE_MAX_SIZE * 1024 * 1024,
            backupCount=cfg.LOGGING_FILE_MAX_FILES,
            encoding=None, delay=0
        )

        logfile_handler.setLevel(cfg.LOGGING_LEVEL_FILE)
        logfile_handler.setFormatter(logging.Formatter(get_format(logger_level)))
        logger.addHandler(logfile_handler)
        logger_level = min(logger_level, cfg.LOGGING_LEVEL_FILE)

    logconsole_handler = logging.StreamHandler()
    logconsole_handler.setLevel(cfg.LOGGING_LEVEL_CONSOLE)
    logconsole_handler.setFormatter(logging.Formatter(get_format(logger_level)))
    logger.addHandler(logconsole_handler)

    logger.setLevel(logger_level) 
开发者ID:ParadoxAlarmInterface,项目名称:pai,代码行数:24,代码来源:main.py

示例10: init_logging

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import RotatingFileHandler [as 别名]
def init_logging():
    global logger
    # Setting rotating files number to 5 and each will be of 1MB
    server_log_file = RotatingFileHandler(
                                            LOGGING_FILE,
                                            maxBytes=10000,
                                            backupCount=5
                                        )
    logger = logging.getLogger()
    '''
    Logging level is set to INFO
    It will log all log messages with INFO, WARNING, ERROR and CRITICAL
    To enable debug logging, change the INFO to DEBUG
    Levels hierarchy CRITICAL>ERROR>WARNING>INFO>DEBUG>NOTSET
    '''
    logger.setLevel(logging.INFO)
    formatter = logging.Formatter(LOGGING_FORMAT)
    server_log_file.setFormatter(formatter)

    logger.addHandler(server_log_file) 
开发者ID:sodafoundation,项目名称:orchestration,代码行数:22,代码来源:config.py

示例11: get_logger

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import RotatingFileHandler [as 别名]
def get_logger(filename, level=logging.INFO):
    azure_logger = logging.getLogger("azure.eventhub")
    azure_logger.setLevel(level)
    uamqp_logger = logging.getLogger("uamqp")
    uamqp_logger.setLevel(logging.INFO)

    formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
    console_handler = logging.StreamHandler(stream=sys.stdout)
    console_handler.setFormatter(formatter)
    if not azure_logger.handlers:
        azure_logger.addHandler(console_handler)
    if not uamqp_logger.handlers:
        uamqp_logger.addHandler(console_handler)

    if filename:
        file_handler = RotatingFileHandler(filename, maxBytes=20*1024*1024, backupCount=3)
        file_handler.setFormatter(formatter)
        azure_logger.addHandler(file_handler)
        uamqp_logger.addHandler(file_handler)

    return azure_logger 
开发者ID:Azure,项目名称:azure-event-hubs-python,代码行数:23,代码来源:test_longrunning_send.py

示例12: get_logger

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import RotatingFileHandler [as 别名]
def get_logger(filename, level=logging.INFO):
    azure_logger = logging.getLogger("azure.eventprocessorhost")
    azure_logger.setLevel(level)
    uamqp_logger = logging.getLogger("uamqp")
    uamqp_logger.setLevel(logging.INFO)

    formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
    console_handler = logging.StreamHandler(stream=sys.stdout)
    console_handler.setFormatter(formatter)
    if not azure_logger.handlers:
        azure_logger.addHandler(console_handler)
    if not uamqp_logger.handlers:
        uamqp_logger.addHandler(console_handler)

    if filename:
        file_handler = RotatingFileHandler(filename, maxBytes=20*1024*1024, backupCount=3)
        file_handler.setFormatter(formatter)
        azure_logger.addHandler(file_handler)
        uamqp_logger.addHandler(file_handler)

    return azure_logger 
开发者ID:Azure,项目名称:azure-event-hubs-python,代码行数:23,代码来源:test_longrunning_eph_with_context.py

示例13: get_logger

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import RotatingFileHandler [as 别名]
def get_logger(filename, level=logging.INFO):
    azure_logger = logging.getLogger("azure.eventhub")
    azure_logger.setLevel(level)
    uamqp_logger = logging.getLogger("uamqp")
    uamqp_logger.setLevel(logging.INFO)

    formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
    console_handler = logging.StreamHandler(stream=sys.stdout)
    console_handler.setFormatter(formatter)
    if not azure_logger.handlers:
        azure_logger.addHandler(console_handler)
    if not uamqp_logger.handlers:
        uamqp_logger.addHandler(console_handler)

    if filename:
        file_handler = RotatingFileHandler(filename, maxBytes=5*1024*1024, backupCount=2)
        file_handler.setFormatter(formatter)
        azure_logger.addHandler(file_handler)

    return azure_logger 
开发者ID:Azure,项目名称:azure-event-hubs-python,代码行数:22,代码来源:__init__.py

示例14: get_logger

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import RotatingFileHandler [as 别名]
def get_logger(self):
    log_file_dir = self.save_path
    log_file_name = os.path.join(log_file_dir, 'train.log')
    if not os.path.exists(log_file_dir):
      os.makedirs(log_file_dir)
    logger = logging.getLogger()
    # Debug = write everything
    logger.setLevel(logging.DEBUG)

    formatter = logging.Formatter('%(asctime)s :: %(levelname)s :: %(message)s')
    file_handler = RotatingFileHandler(log_file_name, 'a', 1000000, 1)
    file_handler.setLevel(logging.INFO)
    file_handler.setFormatter(formatter)
    logger.addHandler(file_handler)

    steam_handler = logging.StreamHandler()
    steam_handler.setLevel(logging.INFO)
    logger.addHandler(steam_handler)

    return logger 
开发者ID:easonnie,项目名称:combine-FEVER-NSMN,代码行数:22,代码来源:nn_config.py

示例15: set_logging

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import RotatingFileHandler [as 别名]
def set_logging():
    global logger

    logging.basicConfig(format='%(asctime)s - %(lineno)d - %(funcName)s - %(levelname)s - %(message)s',
                        level=logging.INFO)
    DEFAULT_JSON_OPTIONS.datetime_representation = 2

    logger = logging.getLogger("yeti_to_elastic")

    formatter = logging.Formatter('%(asctime)s - %(lineno)d - %(funcName)s - %(levelname)s - %(message)s')

    # You may change here the path for the log file
    handler = RotatingFileHandler('yeti_to_elastic.log', maxBytes=20000, backupCount=5)
    handler.setFormatter(formatter)
    handler.setLevel(logging.INFO)

    logger.addHandler(handler) 
开发者ID:yeti-platform,项目名称:yeti,代码行数:19,代码来源:yeti_to_elasticsearch.py


注:本文中的logging.handlers.RotatingFileHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。