Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setup(level=logging.WARNING, outputs=[output.STDERR], program_name=None,
capture_warnings=True):
"""Setup Python logging.
This will setup basic handlers for Python logging.
:param level: Root log level.
:param outputs: Iterable of outputs to log to.
:param program_name: The name of the program. Auto-detected if not set.
:param capture_warnings: Capture warnings from the `warnings' module.
"""
root_logger = logging.getLogger(None)
# Remove all handlers
for handler in list(root_logger.handlers):
root_logger.removeHandler(handler)
def get_logger(level=logging.INFO):
logdir = pathlib.Path.home().joinpath('.logs')
if not logdir.exists():
logdir.mkdir(parents=True)
daiquiri.setup(outputs=(
daiquiri.output.STDERR,
daiquiri.output.File(directory=logdir)
), level=level)
logger = daiquiri.getLogger()
if os.getenv('FIRE_DEBUG'):
logger.setLevel(logging.DEBUG)
return logger
def cli(verbose=0):
"""Tagger for fabric8-analytics."""
# hack based on num values of logging.DEBUG, logging.INFO, ...
level = max(logging.WARNING - verbose * 10, logging.DEBUG)
daiquiri.setup(outputs=(daiquiri.output.STDERR,), level=level)
workers = utils.get_default_workers()
conf.set_default("workers", workers, group="metricd")
conf.set_default("parallel_operations", workers)
conf(args, project='gnocchi', validate_default_values=True,
default_config_files=default_config_files,
version=gnocchi.__version__)
utils.parallel_map.MAX_WORKERS = conf.parallel_operations
if not log_to_std and (conf.log_dir or conf.log_file):
outputs = [daiquiri.output.File(filename=conf.log_file,
directory=conf.log_dir)]
else:
outputs = [daiquiri.output.STDERR]
if conf.use_syslog:
outputs.append(
daiquiri.output.Syslog(facility=conf.syslog_log_facility))
if conf.use_journal:
outputs.append(daiquiri.output.Journal())
daiquiri.setup(outputs=outputs)
if logging_level is None:
if conf.debug:
logging_level = logging.DEBUG
elif conf.verbose:
logging_level = logging.INFO
else:
logging_level = logging.WARNING