diff --git a/lib/core/common.py b/lib/core/common.py index b8b0a1cdd..cdc4c0e6f 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -78,8 +78,10 @@ from lib.core.exception import sqlmapMissingDependence from lib.core.exception import sqlmapSilentQuitException from lib.core.exception import sqlmapSyntaxException from lib.core.log import FORMATTER +from lib.core.log import LEVEL_ATTRS +from lib.core.log import LEVEL_COLORS +from lib.core.log import LEVEL_ON_COLORS from lib.core.optiondict import optDict -from lib.core.settings import COLOR_MAP from lib.core.settings import CUSTOM_INJECTION_MARK_CHAR from lib.core.settings import DEFAULT_COOKIE_DELIMITER from lib.core.settings import DEFAULT_GET_POST_DELIMITER @@ -696,14 +698,12 @@ def singleTimeLogMessage(message, level=logging.INFO, flag=None): logger.log(level, message) def setColor(message, bold=False): - retVal = message level = extractRegexResult(r"\A\s*\[(?P[A-Z ]+)\]", message) if level: - attrs = ('bold',) if (level == "CRITICAL" or bold) else None - on_color = 'on_red' if level == "CRITICAL" else None - color = COLOR_MAP.get(level) - retVal = colored(message, color=color, on_color=on_color, attrs=attrs) + retVal = colored(message, color=LEVEL_COLORS.get(level), on_color=LEVEL_ON_COLORS.get(level), attrs=LEVEL_ATTRS.get(level)) + else: + retVal = message return retVal diff --git a/lib/core/log.py b/lib/core/log.py index 1e3a883a7..8467b2a0c 100644 --- a/lib/core/log.py +++ b/lib/core/log.py @@ -18,6 +18,26 @@ logging.addLevelName(CUSTOM_LOGGING.TRAFFIC_IN, "TRAFFIC IN") LOGGER = logging.getLogger("sqlmapLog") +LEVEL_COLORS = { + "CRITICAL": "white", + "ERROR": "red", + "WARNING": "yellow", + "INFO": "green", + "DEBUG": "blue", + "PAYLOAD": "magenta", + "TRAFFIC OUT": "cyan", + "TRAFFIC IN": "grey" + } + +LEVEL_ON_COLORS = { + "CRITICAL": "on_red", + } + +LEVEL_ATTRS = { + "CRITICAL": ('bold',), + } + + try: import ctypes LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout) diff --git a/lib/core/settings.py b/lib/core/settings.py index 737b28d5d..02ebd8cd5 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -268,17 +268,6 @@ BASIC_HELP_ITEMS = ( "wizard" ) -COLOR_MAP = { - "CRITICAL": "white", - "ERROR": "red", - "WARNING": "yellow", - "INFO": "green", - "DEBUG": "blue", - "PAYLOAD": "magenta", - "TRAFFIC OUT": "cyan", - "TRAFFIC IN": "grey" - } - # string representation for NULL value NULL = "NULL"