Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
john-tornblom committed Sep 24, 2023
1 parent ade40b3 commit bff2384
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions klogfmt.py
Expand Up @@ -25,7 +25,7 @@ class ColorFormatter(logging.Formatter):
red = "\x1b[31;20m"
bold_red = "\x1b[31;1m"
reset = "\x1b[0m"
format = "[%(asctime)s] %(name)s: %(message)s"
format = "[%(asctime)s] %(message)s"

FORMATS = {
logging.DEBUG: grey + format + reset,
Expand All @@ -45,6 +45,10 @@ def format(self, record):
sh.setFormatter(ColorFormatter())
sh.setLevel(logging.DEBUG)

logger = logging.getLogger('klog')
logger.addHandler(sh)
logger.setLevel(logging.DEBUG)


def logline(line):
priority = 118
Expand All @@ -57,24 +61,7 @@ def logline(line):
facility = priority >> 3
severity = priority & 7

match = re.match('\[(.*?)\]', line)
category = ''

if match:
category = match.group(1)
line = line[len(category)+2:]

if line.startswith('[ERROR]'):
severity = 3
line = line[7:]

if not category in LOGGERS:
logger = logging.getLogger(category)
logger.addHandler(sh)
logger.setLevel(logging.DEBUG)
LOGGERS[category] = logger

LOGGERS[category].log(LEVELS[severity], line.strip())
logger.log(LEVELS[severity], line.strip())


for line in sys.stdin:
Expand Down

0 comments on commit bff2384

Please sign in to comment.