Some more refactoring

This commit is contained in:
Miroslav Stampar 2012-07-11 20:29:48 +02:00
parent c6464b44be
commit 72378d4f61
2 changed files with 6 additions and 25 deletions

View File

@ -78,9 +78,7 @@ from lib.core.exception import sqlmapMissingDependence
from lib.core.exception import sqlmapSilentQuitException from lib.core.exception import sqlmapSilentQuitException
from lib.core.exception import sqlmapSyntaxException from lib.core.exception import sqlmapSyntaxException
from lib.core.log import FORMATTER from lib.core.log import FORMATTER
from lib.core.log import LEVEL_ATTRS from lib.core.log import LOGGER_HANDLER
from lib.core.log import LEVEL_COLORS
from lib.core.log import LEVEL_ON_COLORS
from lib.core.optiondict import optDict from lib.core.optiondict import optDict
from lib.core.settings import CUSTOM_INJECTION_MARK_CHAR from lib.core.settings import CUSTOM_INJECTION_MARK_CHAR
from lib.core.settings import DEFAULT_COOKIE_DELIMITER from lib.core.settings import DEFAULT_COOKIE_DELIMITER
@ -698,10 +696,13 @@ def singleTimeLogMessage(message, level=logging.INFO, flag=None):
logger.log(level, message) logger.log(level, message)
def setColor(message, bold=False): def setColor(message, bold=False):
message = "[TRAFFIC IN] " + message
level = extractRegexResult(r"\A\s*\[(?P<result>[A-Z ]+)\]", message) level = extractRegexResult(r"\A\s*\[(?P<result>[A-Z ]+)\]", message)
if level: _ = LOGGER_HANDLER.level_map.get(logging._levelNames.get(level))
retVal = colored(message, color=LEVEL_COLORS.get(level), on_color=LEVEL_ON_COLORS.get(level), attrs=LEVEL_ATTRS.get(level)) if _:
background, foreground, bold = _
retVal = colored(message, color=foreground, on_color="on_%s" % background if background else None, attrs=("bold",) if bold else None)
else: else:
retVal = message retVal = message

View File

@ -18,26 +18,6 @@ logging.addLevelName(CUSTOM_LOGGING.TRAFFIC_IN, "TRAFFIC IN")
LOGGER = logging.getLogger("sqlmapLog") 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: try:
import ctypes import ctypes
LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout) LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout)