Commit 5e3bad17 authored by Lars Bärring's avatar Lars Bärring Committed by Klaus Zimmermann
Browse files

Improved logging setup (closes #143)

parent 0a1c1ff9
......@@ -14,12 +14,24 @@ from .datahandling import prepare_input_data, save
from .metadata import load_metadata
logging.basicConfig(level=logging.INFO)
LOG_LEVELS = {
'debug': logging.DEBUG,
'info': logging.INFO,
'warning': logging.WARNING,
'error': logging.ERROR,
'critical': logging.CRITICAL,
}
def parse_args():
parser = argparse.ArgumentParser(
description=(f'A climate index thing, version {__version__}.'))
parser.add_argument('-l', '--log-level', choices=LOG_LEVELS.keys(),
default='info',
help='the lowest priority level '
'of log messages to display')
parser.add_argument('-v', '--verbose', action='store_true',
help='write more detailed log messages')
parser.add_argument('-e', '--deactivate-error-tracking',
action='store_true',
help='deactivate sentry based error tracking')
......@@ -43,6 +55,15 @@ def parse_args():
return parser.parse_args()
def setup_logging(log_level, verbose=False):
if verbose:
format = ('%(relativeCreated)8dms:%(filename)s:%(funcName)s() '
'%(levelname)s:%(name)s:%(message)s')
else:
format = '%(levelname)s:%(name)s:%(message)s'
logging.basicConfig(level=LOG_LEVELS[log_level], format=format)
def init_sentry():
logging.info('Activating sentry')
sentry_sdk.init(
......@@ -109,6 +130,7 @@ def do_main(index_catalog, requested_indices, datafiles,
def main():
args = parse_args()
setup_logging(args.log_level, args.verbose)
if not args.deactivate_error_tracking:
init_sentry()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment