Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
Configure the chaostoolkit logger.
By default logs as strings to stdout and the given file. When `log_format`
is `"json"`, records are set to the console as JSON strings but remain
as strings in the log file. The rationale is that the log file is mostly
for grepping purpose while records written to the console can be forwarded
out of band to anywhere else.
"""
log_level = logging.INFO
# we define colors ourselves as critical is missing in default ones
colors = {
logging.DEBUG: ForegroundColors.CYAN,
logging.INFO: ForegroundColors.GREEN,
logging.WARNING: ForegroundColors.YELLOW,
logging.ERROR: ForegroundColors.RED,
logging.CRITICAL: ForegroundColors.RED
}
fmt = "%(color)s[%(asctime)s %(levelname)s]%(end_color)s %(message)s"
if verbose:
log_level = logging.DEBUG
fmt = "%(color)s[%(asctime)s %(levelname)s] "\
"[%(module)s:%(lineno)d]%(end_color)s %(message)s"
formatter = LogFormatter(
fmt=fmt, datefmt="%Y-%m-%d %H:%M:%S", colors=colors)
if log_format == 'json':
fmt = "(process) (asctime) (levelname) (module) (lineno) (message)"
if context_id:
fmt = "(context_id) {}".format(fmt)
formatter = jsonlogger.JsonFormatter(
log_file: str = None, logger_name: str = "chaostoolkit",
context_id: str = None):
"""
Configure the chaostoolkit logger.
By default logs as strings to stdout and the given file. When `log_format`
is `"json"`, records are set to the console as JSON strings but remain
as strings in the log file. The rationale is that the log file is mostly
for grepping purpose while records written to the console can be forwarded
out of band to anywhere else.
"""
log_level = logging.INFO
# we define colors ourselves as critical is missing in default ones
colors = {
logging.DEBUG: ForegroundColors.CYAN,
logging.INFO: ForegroundColors.GREEN,
logging.WARNING: ForegroundColors.YELLOW,
logging.ERROR: ForegroundColors.RED,
logging.CRITICAL: ForegroundColors.RED
}
fmt = "%(color)s[%(asctime)s %(levelname)s]%(end_color)s %(message)s"
if verbose:
log_level = logging.DEBUG
fmt = "%(color)s[%(asctime)s %(levelname)s] "\
"[%(module)s:%(lineno)d]%(end_color)s %(message)s"
formatter = LogFormatter(
fmt=fmt, datefmt="%Y-%m-%d %H:%M:%S", colors=colors)
if log_format == 'json':
fmt = "(process) (asctime) (levelname) (module) (lineno) (message)"
if context_id: