From e1ff6d2e73641addec59862ad0287afc8dac99a0 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sun, 5 Apr 2020 15:24:51 +0200 Subject: [PATCH] slightly rework of the log output formatting --- CHANGELOG.md | 6 +++--- ansiblelater/logger.py | 12 +++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98b8d13..e0abdf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,3 @@ -* BUGFIX - * replace removed dependency `ansible.module_utils.parsing.convert_bool` - * decode task actions to prevent errors on multiline strings +* ENHANCEMENT + * improve ANSIBLE0001 logic to avoid false positive results + * improve log output readability diff --git a/ansiblelater/logger.py b/ansiblelater/logger.py index c96352b..bc01180 100644 --- a/ansiblelater/logger.py +++ b/ansiblelater/logger.py @@ -9,7 +9,7 @@ import colorama from pythonjsonlogger import jsonlogger from six import iteritems -CONSOLE_FORMAT = "%(levelname)s: %(message)s" +CONSOLE_FORMAT = "%(levelname)s: {}%(message)s" JSON_FORMAT = "(asctime) (levelname) (message)" @@ -63,6 +63,7 @@ class MultilineFormatter(logging.Formatter): def format(self, record): # noqa record.msg = record.msg.replace("\n", "\n{}... ".format(colorama.Style.RESET_ALL)) + record.msg = record.msg + "\n" return logging.Formatter.format(self, record) @@ -157,22 +158,22 @@ def _get_critical_handler(json=False): def critical(message): """Format critical messages and return string.""" - return color_text(colorama.Fore.RED, "{}".format(message)) + return color_text(colorama.Fore.RED, message) def error(message): """Format error messages and return string.""" - return color_text(colorama.Fore.RED, "{}".format(message)) + return color_text(colorama.Fore.RED, message) def warn(message): """Format warn messages and return string.""" - return color_text(colorama.Fore.YELLOW, "{}".format(message)) + return color_text(colorama.Fore.YELLOW, message) def info(message): """Format info messages and return string.""" - return color_text(colorama.Fore.BLUE, "{}".format(message)) + return color_text(colorama.Fore.BLUE, message) def color_text(color, msg): @@ -184,4 +185,5 @@ def color_text(color, msg): :returns: string """ + msg = msg.format(colorama.Style.BRIGHT) return "{}{}{}".format(color, msg, colorama.Style.RESET_ALL)