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


Python handlers.append方法代码示例

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


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

示例1: multi_func

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import append [as 别名]
def multi_func():

    # 启动多进程
    pool = multiprocessing.Pool(multiprocessing.cpu_count())

    setup_logger('logs/MyLog')
    logger = get_logger()
    logger.info('main process')
    l = []

    for i in range(0,10):
        l.append(pool.apply_async(single_func,(i,)))

    results = [res.get() for res in l]

    pool.close()
    pool.join() 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:setup_logger.py

示例2: configurelogging

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import append [as 别名]
def configurelogging():
    _LOGGER.setLevel(logging.DEBUG)
    formatter = logging.Formatter(
        '%(asctime)s - [%(process)d] - %(levelname)s - %(message)s',
        '%Y-%m-%d %H:%M:%S')

    handlers = []
    log_level = logging.INFO

    if os.access(os.path.dirname(LOG_FILE), os.W_OK):
        fileh = logging.handlers.RotatingFileHandler(
            LOG_FILE, maxBytes=5 * M, backupCount=5)
        handlers.append(fileh)

    if os.path.exists(ENABLE_DEV_LOGGING_FILE) or not handlers:
        handlers.append(logging.StreamHandler(sys.stdout))
        log_level = logging.DEBUG

    # Configure and add all handlers
    for handler in handlers:
        handler.setLevel(log_level)
        handler.setFormatter(formatter)
        _LOGGER.addHandler(handler)

    signal.signal(signal.SIGPIPE, signal.SIG_DFL) 
开发者ID:xenserver,项目名称:xscontainer,代码行数:27,代码来源:log.py

示例3: getFilesToDelete

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import append [as 别名]
def getFilesToDelete(self):
        """获得过期需要删除的日志文件"""
        #分离出日志文件夹绝对路径
        #split返回一个元组(absFilePath,fileName)
        #例如:split('I:\ScripPython\char4\mybook\util\logs\mylog.2017-03-19)
        #返回(I:\ScripPython\char4\mybook\util\logs, mylog.2017-03-19)
        # _ 表示占位符,没什么实际意义,
        dirName,_ = os.path.split(self.baseFilename)
        fileNames = os.listdir(dirName)
        result = []
        #self.prefix 为日志文件名 列如:mylog.2017-03-19 中的 mylog
        #加上 点号 . 方便获取点号后面的日期
        prefix = self.prefix + '.'
        plen = len(prefix)
        for fileName in fileNames:
            if fileName[:plen] == prefix:
                #日期后缀 mylog.2017-03-19 中的 2017-03-19
                suffix = fileName[plen:]
                #匹配符合规则的日志文件,添加到result列表中
                if re.compile(self.extMath).match(suffix):
                    result.append(os.path.join(dirName,fileName))
        result.sort()

        #返回  待删除的日志文件
        #   多于 保留文件个数 backupCount的所有前面的日志文件。
        if len(result) < self.backupCount:
            result = []
        else:
            result = result[:len(result) - self.backupCount]
        return result 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:32,代码来源:setup_logger.py

示例4: _update_handlers

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import append [as 别名]
def _update_handlers(self, logger):
        logging._acquireLock()
        try:
            for handler in logger.handlers[:]:
                logger.removeHandler(handler)

            handlers = []

            partial_new_excepthook = new_excepthook
            partial_new_print_exception = new_print_exception

            if self.log_output_type & conf.LogOutputType.console:
                stream_handler = self._create_stream_handler()
                handlers.append(stream_handler)

                partial_new_excepthook = partial(partial_new_excepthook, console=True)
                partial_new_print_exception = partial(partial_new_print_exception, console=True)
            else:
                partial_new_excepthook = partial(partial_new_excepthook, console=False)
                partial_new_print_exception = partial(partial_new_print_exception, console=False)

            if self.log_output_type & conf.LogOutputType.file and self.log_file_location:
                self._update_log_file_path()

                file_handler = self._create_file_handler()
                handlers.append(file_handler)

                sys.excepthook = partial(partial_new_excepthook, output_file=file_handler.stream)
                traceback.print_exception = partial(partial_new_print_exception, output_file=file_handler.stream)
            else:
                sys.excepthook = partial(partial_new_excepthook, output_file=None)
                traceback.print_exception = partial(partial_new_print_exception, output_file=None)

            logging.basicConfig(handlers=handlers,
                                format=self._log_format,
                                datefmt="%Y-%m-%d %H:%M:%S",
                                level=self._log_level)
        finally:
            logging._releaseLock() 
开发者ID:icon-project,项目名称:loopchain,代码行数:41,代码来源:configuration.py

示例5: init_logger

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import append [as 别名]
def init_logger(self) -> None:
        try:
            log_path = self.get_app_config_path()
        except AttributeError:
            if sys.platform == 'win32':
                log_path = os.path.join(QDir.homePath(), 'AppData', 'Local', qApp.applicationName().lower())
            elif sys.platform == 'darwin':
                log_path = os.path.join(QDir.homePath(), 'Library', 'Preferences', qApp.applicationName().lower())
            else:
                log_path = os.path.join(QDir.homePath(), '.config', qApp.applicationName().lower())
        os.makedirs(log_path, exist_ok=True)
        self.console = ConsoleWidget(self)
        self.consoleLogger = ConsoleHandler(self.console)
        handlers = [logging.handlers.RotatingFileHandler(os.path.join(log_path, '%s.log'
                                                                      % qApp.applicationName().lower()),
                                                         maxBytes=1000000, backupCount=1),
                    self.consoleLogger]
        if self.parser.isSet(self.debug_option) or self.verboseLogs:
            # noinspection PyTypeChecker
            handlers.append(logging.StreamHandler())
        logging.setLoggerClass(VideoLogger)
        logging.basicConfig(handlers=handlers,
                            format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                            datefmt='%Y-%m-%d %H:%M',
                            level=logging.INFO)
        logging.captureWarnings(capture=True)
        sys.excepthook = MainWindow.log_uncaught_exceptions
        if os.getenv('DEBUG', False):
            logging.info('appconfig folder: {}'.format(log_path)) 
开发者ID:ozmartian,项目名称:vidcutter,代码行数:31,代码来源:__main__.py

示例6: _create_file_handler

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import append [as 别名]
def _create_file_handler(site_config, config_prefix):
    filename = site_config.get(f'{config_prefix}/name')
    timestamp = site_config.get(f'{config_prefix}/timestamp')
    if timestamp:
        basename, ext = os.path.splitext(filename)
        filename = '%s_%s%s' % (basename, time.strftime(timestamp), ext)

    append = site_config.get(f'{config_prefix}/append')
    return logging.handlers.RotatingFileHandler(filename,
                                                mode='a+' if append else 'w+') 
开发者ID:eth-cscs,项目名称:reframe,代码行数:12,代码来源:logging.py

示例7: _create_filelog_handler

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import append [as 别名]
def _create_filelog_handler(site_config, config_prefix):
    basedir = os.path.abspath(site_config.get(f'{config_prefix}/basedir'))
    prefix  = site_config.get(f'{config_prefix}/prefix')
    filename_patt = os.path.join(basedir, prefix)
    append = site_config.get(f'{config_prefix}/append')
    return MultiFileHandler(filename_patt, mode='a+' if append else 'w+') 
开发者ID:eth-cscs,项目名称:reframe,代码行数:8,代码来源:logging.py

示例8: _extract_handlers

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import append [as 别名]
def _extract_handlers(site_config, handlers_group):
    handler_prefix = f'logging/0/{handlers_group}'
    handlers_list = site_config.get(handler_prefix)
    handlers = []
    for i, handler_config in enumerate(handlers_list):
        handler_type = handler_config['type']
        if handler_type == 'file':
            hdlr = _create_file_handler(site_config, f'{handler_prefix}/{i}')
        elif handler_type == 'filelog':
            hdlr = _create_filelog_handler(
                site_config, f'{handler_prefix}/{i}'
            )
        elif handler_type == 'syslog':
            hdlr = _create_syslog_handler(site_config, f'{handler_prefix}/{i}')
        elif handler_type == 'stream':
            hdlr = _create_stream_handler(site_config, f'{handler_prefix}/{i}')
        elif handler_type == 'graylog':
            hdlr = _create_graylog_handler(
                site_config, f'{handler_prefix}/{i}'
            )
            if hdlr is None:
                getlogger().warning('could not initialize the '
                                    'graylog handler; ignoring ...')
                continue
        else:
            # Should not enter here
            raise AssertionError(f"unknown handler type: {handler_type}")

        level = site_config.get(f'{handler_prefix}/{i}/level')
        fmt = site_config.get(f'{handler_prefix}/{i}/format')
        datefmt = site_config.get(f'{handler_prefix}/{i}/datefmt')
        hdlr.setFormatter(RFC3339Formatter(fmt=fmt, datefmt=datefmt))
        hdlr.setLevel(_check_level(level))
        handlers.append(hdlr)

    return handlers 
开发者ID:eth-cscs,项目名称:reframe,代码行数:38,代码来源:logging.py

示例9: remove_handlers

# 需要导入模块: from logging import handlers [as 别名]
# 或者: from logging.handlers import append [as 别名]
def remove_handlers():
    """Remove root services_logging handlers."""
    handlers = []
    for handler in logging.root.handlers:
        if not isinstance(handler, logging.StreamHandler):
            handlers.append(handler)
    logging.root.handlers = handlers 
开发者ID:pytest-dev,项目名称:pytest-services,代码行数:9,代码来源:log.py


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