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


Python handlers.TimedRotatingFileHandler方法代码示例

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


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

示例1: logger

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import TimedRotatingFileHandler [as 别名]
def logger():
    logger = logging.getLogger('testlog')

    logHandler = TimedRotatingFileHandler(filename="logfile", when="midnight")
    logFormatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
    logHandler.setFormatter(logFormatter)



    if not logger.handlers:
        streamhandler = logging.StreamHandler()
        streamhandler.setLevel(logging.ERROR)
        formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(name)s - %(message)s')
        streamhandler.setFormatter(formatter)

        logger.addHandler(streamhandler)
        logger.addHandler(logHandler)


    # logger.error(message)
    return logger 
开发者ID:makelove,项目名称:Python_Master_Courses,代码行数:23,代码来源:问题2.py

示例2: InitiateLogger

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import TimedRotatingFileHandler [as 别名]
def InitiateLogger(name="Timeline"):
    Constants.TIMELINE_LOGGER = name
    Timeline_logger = logging.getLogger(name)

    Timeline_stream = logging.StreamHandler()
    LogFormat = logging.Formatter("%(asctime)s [%(levelname)s]\t : %(message)s", "%H:%M")
    Timeline_stream.setFormatter(LogFormat)
    Timeline_logger.addHandler(Timeline_stream)
    Timeline_logger.setLevel(logging.DEBUG)

    handler = TimedRotatingFileHandler('./logs/TimelineLogs.log', when="d", interval=1)
    Timeline_logger.addHandler(handler)

    Timeline_logger.debug("Timeline Logger::Initiated")

    return Timeline_logger 
开发者ID:Times-0,项目名称:Timeline,代码行数:18,代码来源:Start.py

示例3: __init__

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import TimedRotatingFileHandler [as 别名]
def __init__(self,filename=os.path.join(config_dir,'logs/PyOne.running.log'),level='debug',when='D',backCount=3,fmt='%(asctime)s - %(levelname)s: %(message)s'):
        self.filename=filename
        self.level=level
        self.logger = logging.getLogger(self.filename)
        format_str = logging.Formatter(fmt)#设置日志格式
        self.logger.setLevel(self.level_relations.get(self.level))#设置日志级别
        self.stream_handler = logging.StreamHandler()#往屏幕上输出
        self.stream_handler.setFormatter(format_str) #设置屏幕上显示的格式
        self.file_handler = handlers.TimedRotatingFileHandler(filename=filename,when=when,backupCount=backCount,encoding='utf-8')#往文件里写入#指定间隔时间自动生成文件的处理器
        #实例化TimedRotatingFileHandler
        #interval是时间间隔,backupCount是备份文件的个数,如果超过这个个数,就会自动删除,when是间隔的时间单位,单位有以下几种:
        # S 秒
        # M 分
        # H 小时、
        # D 天、
        # W 每星期(interval==0时代表星期一)
        # midnight 每天凌晨
        self.file_handler.setFormatter(format_str)#设置文件里写入的格式
        self.logger.addHandler(self.stream_handler) #把对象加到logger里
        self.logger.addHandler(self.file_handler) 
开发者ID:abbeyokgo,项目名称:PyOne,代码行数:22,代码来源:logmanage.py

示例4: set_file

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import TimedRotatingFileHandler [as 别名]
def set_file(filename):
    logger = logging.getLogger()
    os.getcwd()
    handler = TimedRotatingFileHandler(filename, 'D', 1, 7)
    fmt = '%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s'
    formatter = logging.Formatter(fmt=fmt, datefmt='%m/%d/%Y %H:%M:%S')

    handler.setFormatter(formatter)
    handler.setLevel(logging.INFO)
    # 屏幕输出
    console = logging.StreamHandler()
    console.setFormatter(formatter)
    console.setLevel(logging.INFO)
    logger.addHandler(console)
    logger.addHandler(handler)
    logger.setLevel(logging.INFO) 
开发者ID:lubosson,项目名称:webinfo-crawler,代码行数:18,代码来源:log.py

示例5: get_handler

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import TimedRotatingFileHandler [as 别名]
def get_handler(class_name, level=None, log_dir=None, log_type=None):
        if not log_type:
            if not LoggerFactory.LOG_DIR or not class_name:
                return logging.StreamHandler()

            if not log_dir:
                log_file = os.path.join(LoggerFactory.LOG_DIR, "{}.log".format(class_name))
            else:
                log_file = os.path.join(log_dir, "{}.log".format(class_name))
        else:
            log_file = os.path.join(log_dir, "fate_flow_{}.log".format(log_type) if level == LoggerFactory.LEVEL else 'error.log')
        formatter = logging.Formatter(LoggerFactory.FORMAT)
        handler = TimedRotatingFileHandler(log_file,
                                           when='D',
                                           interval=1,
                                           backupCount=14,
                                           delay=True)

        if level:
            handler.level=level

        handler.setFormatter(formatter)
        return handler 
开发者ID:FederatedAI,项目名称:FATE,代码行数:25,代码来源:log_utils.py

示例6: _setup_logger

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import TimedRotatingFileHandler [as 别名]
def _setup_logger(self, level, log_file):
        """Setup log level and log file if set"""
        if logger.handlers:
            return
        level = getattr(logging, level.upper())
        logger.setLevel(level)
        formatter = logging.Formatter(
            '[%(levelname)s] %(asctime)s - %(module)s.%(funcName)s() - %(message)s')
        handler = logging.StreamHandler()
        logger.addHandler(handler)
        handler.setFormatter(formatter)
        if not log_file:
            return
        try:
            handler = TimedRotatingFileHandler(log_file)
        except IOError:
            logger.error("Could not write to %s, falling back to stdout",
                         log_file)
        else:
            logger.addHandler(handler)
            handler.setFormatter(formatter) 
开发者ID:vimeo,项目名称:graphite-influxdb,代码行数:23,代码来源:graphite_influxdb.py

示例7: init_logging

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import TimedRotatingFileHandler [as 别名]
def init_logging(logger, level, log_file=None):
    fmt = "%(asctime)s - %(pathname)s - %(funcName)s - %(lineno)d - %(levelname)s - %(message)s"
    datefmt = "%Y-%m-%d %H:%M:%S"
    formatter = logging.Formatter(fmt=fmt, datefmt=datefmt)

    level = getattr(logging, level.upper())
    logger.setLevel(level)

    if log_file:
        from logging.handlers import TimedRotatingFileHandler
        handler = TimedRotatingFileHandler(log_file, when="midnight", interval=1, backupCount=30)
    else:
        handler = logging.StreamHandler()
    handler.setLevel(level)
    handler.setFormatter(formatter)

    logger.addHandler(handler)

##############################################################################
# Configuration 
开发者ID:xgfone,项目名称:snippet,代码行数:22,代码来源:check_music.py

示例8: init_logger

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import TimedRotatingFileHandler [as 别名]
def init_logger(background=False):
    logger.setLevel(logging.DEBUG)
    logging.getLogger('peewee').setLevel(logging.INFO)
    logging.getLogger('apscheduler').setLevel(logging.INFO)
    logging.getLogger('PyQt5').setLevel(logging.INFO)

    # create logging format
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

    # create handlers
    fh = TimedRotatingFileHandler(os.path.join(LOG_DIR, 'vorta.log'),
                                  when='d',
                                  interval=1,
                                  backupCount=5)
    fh.setLevel(logging.DEBUG)
    fh.setFormatter(formatter)
    logger.addHandler(fh)

    if background:
        pass
    else:  # log to console, when running in foreground
        ch = logging.StreamHandler()
        ch.setLevel(logging.DEBUG)
        ch.setFormatter(formatter)
        logger.addHandler(ch) 
开发者ID:borgbase,项目名称:vorta,代码行数:27,代码来源:log.py

示例9: __init__

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import TimedRotatingFileHandler [as 别名]
def __init__(self, *args, **kwargs):
            handlers.TimedRotatingFileHandler.__init__(self, *args, **kwargs)

            self._failure = False

            if not os.path.exists(self._filename):
                return

            timestamp = os.stat(self._filename).st_mtime

            # Use a stand-aside file metadata time instead of the last
            # modification of the log file itself, as the stock
            # implementation does.
            # This is to work-around the increasing rotation intervals
            # on process restart.
            self.rollover_at = self.computeRollover(timestamp) 
开发者ID:etingof,项目名称:snmpsim,代码行数:18,代码来源:log.py

示例10: doRollover

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import TimedRotatingFileHandler [as 别名]
def doRollover(self):
            try:
                handlers.TimedRotatingFileHandler.doRollover(self)

                # note log file creation time
                if os.path.exists(self._filename):
                    os.unlink(self._filename)

                open(self._filename, 'w').close()

                self._failure = False

            except IOError as exc:
                # File rotation seems to fail, postpone the next run
                timestamp = time.time()
                self.rollover_at = self.computeRollover(timestamp)

                if not self._failure:
                    self._failure = True
                    error('Failed to rotate log/timestamp file '
                          '%s: %s' % (self._filename, exc)) 
开发者ID:etingof,项目名称:snmpsim,代码行数:23,代码来源:log.py

示例11: instantiate

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import TimedRotatingFileHandler [as 别名]
def instantiate(p):
  print("*** instantiate ***")
  print(p)
  with rlock:
    global logger
    logger = logging.getLogger("freepydius-logger")
    logger.setLevel(logging.INFO)
    handler = TimedRotatingFileHandler(_LOG_FILE,
                                       when="midnight",
                                       interval=1)
    formatter = logging.Formatter("%(asctime)s %(message)s")
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    log = Log("INSTANCE")
    log.log(( ('Response', 'created'), ))
  # return 0 for success or -1 for failure
  return 0 
开发者ID:enckse,项目名称:freeradius,代码行数:19,代码来源:freepydius.py

示例12: setup_logging

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import TimedRotatingFileHandler [as 别名]
def setup_logging():
    logger = logging.getLogger("")
    logger.setLevel(logging.WARNING)
    file_handler = handlers.TimedRotatingFileHandler(
        os.path.expanduser("~/.mate-i3-applet.log"),
        when="D",
        backupCount=1,
        delay=True,
    )
    file_handler.setFormatter(
        logging.Formatter(
            '[%(levelname)s] %(asctime)s: %(message)s',
            "%Y-%m-%d %H:%M:%S",
        )
    )
    logger.addHandler(file_handler)
    sys.excepthook = exception_handler 
开发者ID:city41,项目名称:mate-i3-applet,代码行数:19,代码来源:log.py

示例13: __setFileHandler__

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import TimedRotatingFileHandler [as 别名]
def __setFileHandler__(self, level=None):
        """
        set file handler
        :param level:
        :return:
        """
        file_name = os.path.join(LOG_PATH, '{name}.log'.format(name=self.name))
        # 设置日志回滚, 保存在log目录, 一天保存一个文件, 保留15天
        file_handler = TimedRotatingFileHandler(filename=file_name, when='D', interval=1, backupCount=15)
        file_handler.suffix = '%Y%m%d.log'
        if not level:
            file_handler.setLevel(self.level)
        else:
            file_handler.setLevel(level)
        formatter = logging.Formatter('%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s')

        file_handler.setFormatter(formatter)
        self.file_handler = file_handler
        self.addHandler(file_handler) 
开发者ID:jhao104,项目名称:proxy_pool,代码行数:21,代码来源:logHandler.py

示例14: __init__

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import TimedRotatingFileHandler [as 别名]
def __init__(self, filename, level='info', when='D', backCount=3,
                 fmt='%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s'):
        self.logger = logging.getLogger(filename)
        format_str = logging.Formatter(fmt)  # 设置日志格式
        self.logger.setLevel(self.level_relations.get(level))  # 设置日志级别
        sh = logging.StreamHandler()  # 往屏幕上输出
        sh.setFormatter(format_str)  # 设置屏幕上显示的格式
        th = handlers.TimedRotatingFileHandler(filename=filename, when=when, backupCount=backCount,
                                               encoding='utf-8')  # 往文件里写入#指定间隔时间自动生成文件的处理器
        # 实例化TimedRotatingFileHandler
        # interval是时间间隔,backupCount是备份文件的个数,如果超过这个个数,就会自动删除,when是间隔的时间单位,单位有以下几种:
        # S 秒
        # M 分
        # H 小时、
        # D 天、
        # W 每星期(interval==0时代表星期一)
        # midnight 每天凌晨
        th.setFormatter(format_str)  # 设置文件里写入的格式
        self.logger.addHandler(sh)  # 把对象加到logger里
        self.logger.addHandler(th) 
开发者ID:jerrychan807,项目名称:WSPIH,代码行数:22,代码来源:logger.py

示例15: load_logger

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import TimedRotatingFileHandler [as 别名]
def load_logger(level, path, name):
    """

    :param level:
    :param path:
    :param name:
    """
    logger = logging.getLogger()  # set up root logger
    if not os.path.exists(path):
        logger.warning("Folder {} not found, creating a new one ...".format(path))
        os.makedirs(path)
    filename = os.path.join(path, name)
    handler = TimedRotatingFileHandler(filename, when='H')
    handler.suffix = "%Y-%m-%d.log"
    handler.extMatch = r"^\d{4}-\d{2}-\d{2}\.log$"

    level = levels[level]
    handler.setLevel(level)  # set level for handler
    formatter = '%(asctime)s - %(name)s - %(levelname)s | [%(filename)s:%(lineno)d] | %(message)s'
    handler.setFormatter(logging.Formatter(formatter))
    logger.addHandler(handler)
    logger.setLevel(level)
    logger.warning("Logger initialized, dumping log in {}".format(filename))
    return logger 
开发者ID:alessiosavi,项目名称:PyRecognizer,代码行数:26,代码来源:util.py


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