Source code for caspia.toolbox.cli.logging

import functools

import click

from caspia.toolbox.logging import setup_logging


[docs]def logging_options(): """ Adds -v, --verbose options and automatically enables logging based on them. """ def decorator(f): @click.option('-v', '--verbose', count=True, help='Increase log verbosity.') @click.option('--log-systemd', is_flag=True, help='Log to systemd instead of stderr.') @click.option('--log-syslog', is_flag=True, help='Log to syslog instead of stderr.') @functools.wraps(f) def wrapped(*args, verbose=None, log_systemd, log_syslog, **kwargs): if verbose is not None: level = 60 - verbose * 20 else: level = None setup_logging(level=level, systemd=log_systemd, syslog=log_syslog) return f(*args, **kwargs) return wrapped return decorator
verbose_option = logging_options