本文整理匯總了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,
)