Add timestamp to build logs

Add timestamps to logs (console and file), updates debrepack
to use utils.py for logging and removes color from file handler
builder.log.

Test Plan:
Pass: build-pkgs -a
Pass: build-image
Pass: repo_manage list
Pass: downloader -s -b

Story: 2008846
Task: 45086

Signed-off-by: Luis Sampaio <luis.sampaio@windriver.com>
Change-Id: If2d76d0d1a6ddd47b6ecc8ed72f9adecbcd354b5
This commit is contained in:
Luis Sampaio 2022-05-02 10:30:58 -07:00
parent 1564e33136
commit e118936e89
3 changed files with 21 additions and 23 deletions

View File

@ -27,6 +27,7 @@ import re
import shutil
import subprocess
import sys
import utils
import urllib.parse
import urllib.request
import yaml
@ -228,22 +229,11 @@ def is_git_repo(path):
class Parser():
level_relations = {
'debug': logging.DEBUG,
'info': logging.INFO,
'warning': logging.WARNING,
'error': logging.ERROR,
'crit': logging.CRITICAL
}
def __init__(self, basedir, output, loglevel='info', srcrepo=None, btype="std"):
def __init__(self, basedir, output, log_level='info', srcrepo=None, btype="std"):
self.logger = logging.getLogger(__name__)
self.logger.setLevel(self.level_relations.get(loglevel))
formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
console = logging.StreamHandler(sys.stdout)
console.setFormatter(formatter)
self.logger.addHandler(console)
utils.set_logger(self.logger, log_level=log_level)
self.strategy = "cengn_first"
if CENGN_STRATEGY is not None:

View File

@ -343,7 +343,7 @@ class SrcDownloader(BaseDownloader):
if not self.parser:
try:
self.parser = debrepack.Parser(build_dir,
recipes_dir, 'debug')
recipes_dir, log_level='debug')
except Exception as e:
logger.error(str(e))
logger.error("Failed to create debrepack parser")

View File

@ -17,12 +17,19 @@
import logging
import os
log_levels = {
'debug': logging.DEBUG,
'info': logging.INFO,
'warning': logging.WARNING,
'error': logging.ERROR,
'crit': logging.CRITICAL
}
def set_logger(logger):
logger.setLevel(logging.DEBUG)
def set_logger(logger, log_level='debug'):
logger.setLevel(log_levels[log_level])
class ColorFormatter(logging.Formatter):
FORMAT = ("$BOLD%(name)-s$RESET - %(levelname)s: %(message)s")
FORMAT = ("%(asctime)s - $BOLD%(name)-s$RESET - %(levelname)s: %(message)s")
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = list(range(8))
@ -58,16 +65,17 @@ def set_logger(logger):
record.levelname = lncolor
return logging.Formatter.format(self, record)
# create console handler and set level to debug
# create log and console handler and set level
fh = logging.FileHandler('/localdisk/builder.log')
fh.setLevel(log_levels[log_level])
fh.setFormatter(ColorFormatter(use_color=False))
logger.addHandler(fh)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setLevel(log_levels[log_level])
ch.setFormatter(ColorFormatter())
logger.addHandler(ch)
fh = logging.FileHandler('/localdisk/builder.log')
fh.setLevel(logging.DEBUG)
fh.setFormatter(ColorFormatter())
logger.addHandler(fh)
logger.propagate = 0