kupferbootstrap/logger.py

28 lines
788 B
Python
Raw Normal View History

2021-08-04 18:36:37 +02:00
import click
2022-05-07 15:27:55 +02:00
import coloredlogs
2021-08-04 18:36:37 +02:00
import logging
import sys
2021-09-12 06:12:39 +02:00
2021-08-04 18:36:37 +02:00
def setup_logging(verbose: bool):
2022-05-07 15:27:55 +02:00
level_colors = coloredlogs.DEFAULT_LEVEL_STYLES | {'info': {'color': 'magenta', 'bright': True}, 'debug': {'color': 'blue', 'bright': True}}
field_colors = coloredlogs.DEFAULT_FIELD_STYLES | {'asctime': {'color': 'white', 'faint': True}}
level = logging.DEBUG if verbose else logging.INFO
2022-05-07 15:27:55 +02:00
coloredlogs.install(
2021-08-04 18:36:37 +02:00
stream=sys.stdout,
2022-05-07 15:27:55 +02:00
fmt='%(asctime)s %(levelname)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
2021-08-08 18:32:42 +02:00
level=level,
2022-05-07 15:27:55 +02:00
level_styles=level_colors,
field_styles=field_colors,
2021-08-04 18:36:37 +02:00
)
logging.debug('Logging set up.')
2021-08-04 18:36:37 +02:00
verbose_option = click.option(
'-v',
'--verbose',
is_flag=True,
2021-08-08 18:32:42 +02:00
help='Enables verbose logging',
2021-08-04 18:36:37 +02:00
)