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


Python logbook.NestedSetup方法代码示例

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


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

示例1: setup_logbook

# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import NestedSetup [as 别名]
def setup_logbook(logfile, logfile_kwargs=None):
  """Return a basic `logbook` setup which logs to `stderr` and to file."""

  if logfile_kwargs is None:
    logfile_kwargs = {}

  logfile_kwargs.setdefault('level', 'DEBUG')
  logfile_kwargs.setdefault('mode', 'w')
  logfile_kwargs.setdefault('bubble', True)
  logfile_kwargs.setdefault('format_string',
      ('--------------------------------------------------------------------------\n'
       '[{record.time} {record.level_name:<8s} {record.channel:>10s}]'
       ' {record.filename:s}:{record.lineno:d}\n{record.message:s}'))

  logbook_setup = logbook.NestedSetup([
    logbook.NullHandler(),
    logbook.more.ColorizedStderrHandler(level='INFO', bubble=False,
      format_string='[{record.level_name:<8s} {record.channel:s}] {record.message:s}'),
    logbook.FileHandler(logfile, **logfile_kwargs),
  ])

  return logbook_setup 
开发者ID:Netflix-Skunkworks,项目名称:stethoscope,代码行数:24,代码来源:utils.py

示例2: post_fork

# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import NestedSetup [as 别名]
def post_fork(server, worker):
    server.log.info('Worker spawned (pid: %s)', worker.pid)

    logging_rotating_file_handler = logging.handlers.RotatingFileHandler(
        config.LOG_FILE_PATH.replace('.log', f'.{worker.pid}.flask.log'),
        maxBytes=5 * 1024 * 1024,
        backupCount=5,
    )

    root_logger = logging.getLogger()
    root_logger.addHandler(logging_rotating_file_handler)
    root_logger.setLevel(logging.CRITICAL)

    logger_setup = logbook.NestedSetup(
        [
            logbook.StreamHandler(sys.stdout, level=logbook.INFO, bubble=True),
            logbook.RotatingFileHandler(
                config.LOG_FILE_PATH.replace('.log', f'.{worker.pid}.log'),
                level=logbook.INFO,
                max_size=5 * 1024 * 1024,
                bubble=True,
            ),
        ]
    )
    logger_setup.push_application() 
开发者ID:snowflakedb,项目名称:SnowAlert,代码行数:27,代码来源:gunicorn_conf.py

示例3: run_plugins

# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import NestedSetup [as 别名]
def run_plugins(hive_path, output_path, plugins, hive_type, partial_hive_path, verbose):
    with logbook.NestedSetup(_get_log_handlers(verbose=verbose)).applicationbound():
        registry_hive = RegistryHive(hive_path, hive_type=hive_type, partial_hive_path=partial_hive_path)
        click.secho('Loaded {} plugins'.format(len(PLUGINS)), fg='white')

        if plugins:
            plugin_names = {x.NAME for x in PLUGINS}
            plugins = plugins.split(',')
            plugins = set(plugins)
            if not plugins.issubset(plugin_names):
                click.secho('Invalid plugin names given: {}'.format(','.join(set(plugins) - plugin_names)), fg='red')
                click.secho('Use --help or -h to get list of plugins and their descriptions', fg='red')
                return

        # Run relevant plugins
        plugin_results = run_relevant_plugins(registry_hive, as_json=True, plugins=plugins)

        # If output path was set, dump results to disk
        if output_path:
            with open(output_path, 'w') as f:
                f.write(json.dumps(plugin_results, indent=4))
        else:
            print(json.dumps(plugin_results, indent=4))
        click.secho('Finished: {}/{} plugins matched the hive type'.format(len(plugin_results), len(PLUGINS)),
                    fg='green') 
开发者ID:mkorman90,项目名称:regipy,代码行数:27,代码来源:cli.py

示例4: reg_diff

# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import NestedSetup [as 别名]
def reg_diff(first_hive_path, second_hive_path, output_path, verbose):
    with logbook.NestedSetup(_get_log_handlers(verbose=verbose)).applicationbound():
        REGDIFF_HEADERS = ['difference', 'first_hive', 'second_hive', 'description']

        found_differences = compare_hives(first_hive_path, second_hive_path, verbose=verbose)
        click.secho('Comparing {} vs {}'.format(os.path.basename(first_hive_path), os.path.basename(second_hive_path)))

        if output_path:
            with open(output_path, 'w') as csvfile:
                csvwriter = csv.writer(csvfile, delimiter='|', quoting=csv.QUOTE_MINIMAL)
                csvwriter.writerow(REGDIFF_HEADERS)
                for difference in found_differences:
                    csvwriter.writerow(difference)
        else:
            click.secho(tabulate(found_differences, headers=REGDIFF_HEADERS,
                                 tablefmt='fancy_grid'))
        click.secho(f'Detected {len(found_differences)} differences', fg='green') 
开发者ID:mkorman90,项目名称:regipy,代码行数:19,代码来源:cli.py

示例5: get_nested_setup

# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import NestedSetup [as 别名]
def get_nested_setup(self):
        nested_log_setup = logbook.NestedSetup(self.handlers)

        return nested_log_setup 
开发者ID:haukurk,项目名称:flask-restapi-recipe,代码行数:6,代码来源:logging.py

示例6: parse_header

# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import NestedSetup [as 别名]
def parse_header(hive_path, verbose):
    with logbook.NestedSetup(_get_log_handlers(verbose=verbose)).applicationbound():
        registry_hive = RegistryHive(hive_path)

        click.secho(tabulate(registry_hive.header.items(), tablefmt='fancy_grid'))

        if registry_hive.header.primary_sequence_num != registry_hive.header.secondary_sequence_num:
            click.secho('Hive is not clean! You should apply transaction logs', fg='red')

        calculated_checksum = calculate_xor32_checksum(registry_hive._stream.read(4096))
        if registry_hive.header.checksum != calculated_checksum:
            click.secho('Hive is not clean! Header checksum does not match', fg='red') 
开发者ID:mkorman90,项目名称:regipy,代码行数:14,代码来源:cli.py

示例7: hive_to_json

# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import NestedSetup [as 别名]
def hive_to_json(hive_path, output_path, registry_path, timeline, hive_type, partial_hive_path, verbose):
    with logbook.NestedSetup(_get_log_handlers(verbose=verbose)).applicationbound():
        registry_hive = RegistryHive(hive_path, hive_type=hive_type, partial_hive_path=partial_hive_path)

        if registry_path:
            try:
                name_key_entry = registry_hive.get_key(registry_path)
            except RegistryKeyNotFoundException as ex:
                logger.debug('Did not find the key: {}'.format(ex))
                return
        else:
            name_key_entry = registry_hive.root

        if timeline and not output_path:
            click.secho('You must provide an output path if choosing timeline output!', fg='red')
            return

        if output_path:
            if timeline:
                with open(output_path, 'w') as csvfile:
                    csvwriter = csv.DictWriter(csvfile, delimiter=',',
                                               quotechar='"', quoting=csv.QUOTE_MINIMAL,
                                               fieldnames=['timestamp', 'subkey_name', 'values_count'])
                    csvwriter.writeheader()
                    for entry in tqdm(registry_hive.recurse_subkeys(name_key_entry, as_json=True)):
                        entry_dict = entry.__dict__
                        path = entry.path
                        csvwriter.writerow({
                            'subkey_name': r'{}\{}'.format(entry.path, path),
                            'timestamp': entry_dict['timestamp'],
                            'values_count': entry_dict['values_count']
                        })
            else:
                dump_hive_to_json(registry_hive, output_path, name_key_entry, verbose)
        else:
            for entry in registry_hive.recurse_subkeys(name_key_entry, as_json=True):
                click.secho(json.dumps(attr.asdict(entry), indent=4)) 
开发者ID:mkorman90,项目名称:regipy,代码行数:39,代码来源:cli.py

示例8: parse_transaction_log

# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import NestedSetup [as 别名]
def parse_transaction_log(hive_path, primary_log_path, secondary_log_path, output_path, verbose):
    with logbook.NestedSetup(_get_log_handlers(verbose=verbose)).applicationbound():
        logger.info(f'Processing hive {hive_path} with transaction log {primary_log_path}')
        if secondary_log_path:
            logger.info(f'Processing hive {hive_path} with secondary transaction log {primary_log_path}')

        restored_hive_path, recovered_dirty_pages_count = apply_transaction_logs(hive_path, primary_log_path,
                                                                                 secondary_log_path=secondary_log_path,
                                                                                 restored_hive_path=output_path,
                                                                                 verbose=verbose)
        if recovered_dirty_pages_count:
            click.secho(
                f'Recovered {recovered_dirty_pages_count} dirty pages. Restored hive is at {restored_hive_path}',
                fg='green') 
开发者ID:mkorman90,项目名称:regipy,代码行数:16,代码来源:cli.py


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