Python logbook.more() Examples
The following are 7
code examples of logbook.more().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
logbook
, or try the search function
.
Example #1
Source File: utils.py From stethoscope with Apache License 2.0 | 6 votes |
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
Example #2
Source File: callback_server.py From threema-msgapi-sdk-python with MIT License | 6 votes |
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 = {}
Example #3
Source File: bin.py From saltyrtc-server-python with MIT License | 5 votes |
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
Example #4
Source File: util.py From threema-msgapi-sdk-python with MIT License | 5 votes |
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)
Example #5
Source File: gateway_client.py From threema-msgapi-sdk-python with MIT License | 5 votes |
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 }
Example #6
Source File: log.py From code-coverage with Mozilla Public License 2.0 | 4 votes |
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, )
Example #7
Source File: log.py From code-review with Mozilla Public License 2.0 | 4 votes |
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, )