當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。