本文整理汇总了Python中logbook.more方法的典型用法代码示例。如果您正苦于以下问题:Python logbook.more方法的具体用法?Python logbook.more怎么用?Python logbook.more使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logbook
的用法示例。
在下文中一共展示了logbook.more方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_logbook
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import more [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
示例2: cli
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import more [as 别名]
def cli(ctx, verbosity, colored):
"""
Command Line Interface. Use --help for details.
"""
if verbosity > 0:
# Enable logging
util.enable_logging(level=_logging_levels[verbosity])
# Get handler class
if colored:
handler_class = logbook.more.ColorizedStderrHandler
else:
handler_class = logbook.StderrHandler
# Set up logging handler
handler = handler_class(level=_logging_levels[verbosity])
handler.push_application()
global _logging_handler
_logging_handler = handler
# Create context object
ctx.obj = {}
示例3: cli
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import more [as 别名]
def cli(ctx: click.Context, verbosity: int, colored: bool) -> None:
"""
Command Line Interface. Use --help for details.
"""
if verbosity > 0:
try:
# noinspection PyUnresolvedReferences
import logbook.more
except ImportError:
click.echo('Please install saltyrtc.server[logging] for logging support.',
err=True)
ctx.exit(code=_ErrorCode.import_error)
# Translate logging level
level = _get_logging_level(verbosity)
# Enable asyncio debug logging if verbosity is high enough
# noinspection PyUnboundLocalVariable
if level <= logbook.DEBUG:
os.environ['PYTHONASYNCIODEBUG'] = '1'
# Enable logging
util.enable_logging(level=level, redirect_loggers={
'asyncio': level,
'websockets': level,
})
# Get handler class
if colored:
handler_class = logbook.more.ColorizedStderrHandler
else:
handler_class = logbook.StderrHandler
# Set up logging handler
handler = handler_class(level=level)
handler.push_application()
ctx.obj['logging_handler'] = handler
示例4: _make_key
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import more [as 别名]
def _make_key(
args, kwargs, typed,
fast_types={int, str, frozenset, type(None)},
kwargs_mark=(object(),),
):
"""
Make a cache key from optionally typed positional and keyword arguments
The key is constructed in a way that is flat as possible rather than
as a nested structure that would take more memory.
If there is only a single argument and its data type is known to cache
its hash value, then that argument is returned without a wrapper. This
saves space and improves lookup speed.
"""
key = args
if kwargs:
sorted_items = sorted(kwargs.items())
key += kwargs_mark
for item in sorted_items:
key += item
else:
sorted_items = []
if typed:
key += tuple(type(v) for v in args)
if kwargs:
key += tuple(type(v) for k, v in sorted_items)
elif len(key) == 1 and type(key[0]) in fast_types:
return key[0]
return _HashedSeq(key)
示例5: cli
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import more [as 别名]
def cli(ctx, verbosity, colored, verify_fingerprint, fingerprint):
"""
Command Line Interface. Use --help for details.
"""
if verbosity > 0:
# Enable logging
util.enable_logging(level=_logging_levels[verbosity])
# Get handler class
if colored:
handler_class = logbook.more.ColorizedStderrHandler
else:
handler_class = logbook.StderrHandler
# Set up logging handler
handler = handler_class(level=_logging_levels[verbosity])
handler.push_application()
global _logging_handler
_logging_handler = handler
# Fingerprint
if fingerprint is not None:
fingerprint = binascii.unhexlify(fingerprint)
# Store on context
ctx.obj = {
'verify_fingerprint': verify_fingerprint,
'fingerprint': fingerprint
}
示例6: init_logger
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import more [as 别名]
def init_logger(
project_name,
channel=None,
level=logbook.INFO,
PAPERTRAIL_HOST=None,
PAPERTRAIL_PORT=None,
sentry_dsn=None,
):
if not channel:
channel = os.environ.get("APP_CHANNEL")
# Output logs on stderr, with color support on consoles
fmt = "{record.time} [{record.level_name:<8}] {record.channel}: {record.message}"
handler = logbook.more.ColorizedStderrHandler(level=level, format_string=fmt)
handler.push_application()
# Log to papertrail
if channel and PAPERTRAIL_HOST and PAPERTRAIL_PORT:
setup_papertrail(project_name, channel, PAPERTRAIL_HOST, PAPERTRAIL_PORT)
# Log to senty
if channel and sentry_dsn:
setup_sentry(project_name, channel, sentry_dsn)
def logbook_factory(*args, **kwargs):
# Logger given to structlog
logbook.compat.redirect_logging()
return logbook.Logger(level=level, *args, **kwargs)
# Setup structlog over logbook, with args list at the end
processors = [
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
UnstructuredRenderer(),
]
structlog.configure(
context_class=structlog.threadlocal.wrap_dict(dict),
processors=processors,
logger_factory=logbook_factory,
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
示例7: init_logger
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import more [as 别名]
def init_logger(
project_name,
channel=None,
level=logbook.INFO,
PAPERTRAIL_HOST=None,
PAPERTRAIL_PORT=None,
SENTRY_DSN=None,
):
if not channel:
channel = os.environ.get("APP_CHANNEL")
# Output logs on stderr, with color support on consoles
fmt = "{record.time} [{record.level_name:<8}] {record.channel}: {record.message}"
handler = logbook.more.ColorizedStderrHandler(level=level, format_string=fmt)
handler.push_application()
# Log to papertrail
if channel and PAPERTRAIL_HOST and PAPERTRAIL_PORT:
setup_papertrail(project_name, channel, PAPERTRAIL_HOST, PAPERTRAIL_PORT)
# Log to senty
if channel and SENTRY_DSN:
setup_sentry(project_name, channel, SENTRY_DSN)
def logbook_factory(*args, **kwargs):
# Logger given to structlog
logbook.compat.redirect_logging()
return logbook.Logger(level=level, *args, **kwargs)
# Setup structlog over logbook, with args list at the end
processors = [
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
UnstructuredRenderer(),
]
structlog.configure(
context_class=structlog.threadlocal.wrap_dict(dict),
processors=processors,
logger_factory=logbook_factory,
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)