buildbot: add console log

This commit is contained in:
JerryXiao 2019-09-06 11:45:12 +08:00
parent 46a71dd65e
commit 7f807b3197
Signed by: Jerry
GPG key ID: 9D9CE43650FF2BAA
5 changed files with 18 additions and 35 deletions

View file

@ -19,7 +19,7 @@ from config import ARCHS, BUILD_ARCHS, BUILD_ARCH_MAPPING, \
MAKEPKG_MAKE_CMD, MAKEPKG_MAKE_CMD_CLEAN, \ MAKEPKG_MAKE_CMD, MAKEPKG_MAKE_CMD_CLEAN, \
GPG_SIGN_CMD, GPG_VERIFY_CMD, UPDATE_INTERVAL, \ GPG_SIGN_CMD, GPG_VERIFY_CMD, UPDATE_INTERVAL, \
MAKEPKG_MAKE_CMD_MARCH, UPLOAD_CMD, \ MAKEPKG_MAKE_CMD_MARCH, UPLOAD_CMD, \
GIT_PULL, GIT_RESET_SUBDIR GIT_PULL, GIT_RESET_SUBDIR, CONSOLE_LOGFILE
from utils import print_exc_plus, background, \ from utils import print_exc_plus, background, \
bash, get_pkg_details_from_name, vercmp, \ bash, get_pkg_details_from_name, vercmp, \
@ -37,7 +37,7 @@ abspath=os.path.dirname(abspath)
os.chdir(abspath) os.chdir(abspath)
logger = logging.getLogger('buildbot') logger = logging.getLogger('buildbot')
configure_logger(logger, logfile='buildbot.log', rotate_size=1024*1024*10) configure_logger(logger, logfile='buildbot.log', rotate_size=1024*1024*10, enable_notify=True, consolelog=CONSOLE_LOGFILE)
# refuse to run in systemd-nspawn # refuse to run in systemd-nspawn
if 'systemd-nspawn' in bash('systemd-detect-virt || true'): if 'systemd-nspawn' in bash('systemd-detect-virt || true'):

View file

@ -8,7 +8,8 @@ from multiprocessing.connection import Client
from time import sleep from time import sleep
from config import REPOD_BIND_ADDRESS, REPOD_BIND_PASSWD, \ from config import REPOD_BIND_ADDRESS, REPOD_BIND_PASSWD, \
MASTER_BIND_ADDRESS, MASTER_BIND_PASSWD MASTER_BIND_ADDRESS, MASTER_BIND_PASSWD, \
CONSOLE_LOGFILE
from utils import print_exc_plus from utils import print_exc_plus
@ -40,36 +41,8 @@ if __name__ == '__main__':
from utils import configure_logger from utils import configure_logger
configure_logger(logger) configure_logger(logger)
def print_log(): def print_log():
import os, re import os
abspath=os.path.abspath(__file__) os.system(f'tail -f {CONSOLE_LOGFILE}')
abspath=os.path.dirname(abspath)
os.chdir(abspath)
def is_debug_msg(msg, DEBUG):
if '- DEBUG -' in msg:
return True
elif re.match(r'[0-9]{4}-[0-9]{2}-[0-9]{2}.*', msg):
return False
else:
return DEBUG
with open('buildbot.log', 'r') as f:
DEBUG = False
lines = list()
lines += f.read().split('\n')
while len(lines) >= 100:
lines.pop(0)
while True:
nlines = f.read().split('\n')
if not lines and \
len(nlines) == 1 and nlines[0] == '':
continue
else:
lines += nlines
for line in lines:
DEBUG = is_debug_msg(line, DEBUG)
if not DEBUG:
print(line)
lines = list()
sleep(1)
try: try:
actions = { actions = {
'info': 'show buildbot info', 'info': 'show buildbot info',

View file

@ -62,3 +62,5 @@ UPLOAD_CMD = 'rsync -avPh \"{src}\" repoupload:/srv/repo/buildbot/repo/updates/'
GIT_PULL = 'git pull' GIT_PULL = 'git pull'
GIT_RESET_SUBDIR = 'git checkout HEAD -- .' GIT_RESET_SUBDIR = 'git checkout HEAD -- .'
CONSOLE_LOGFILE = 'buildbot.log.console'

View file

@ -28,7 +28,7 @@ abspath=os.path.dirname(abspath)
os.chdir(abspath) os.chdir(abspath)
logger = logging.getLogger('buildbot') logger = logging.getLogger('buildbot')
configure_logger(logger, logfile='repod.log', rotate_size=1024*1024*10) configure_logger(logger, logfile='repod.log', rotate_size=1024*1024*10, enable_notify=True)
class pushFm: class pushFm:
def __init__(self): def __init__(self):

View file

@ -261,7 +261,7 @@ def format_exc_plus():
def configure_logger(logger, format='%(asctime)s - %(name)-18s - %(levelname)s - %(message)s', def configure_logger(logger, format='%(asctime)s - %(name)-18s - %(levelname)s - %(message)s',
level=logging.INFO, logfile=None, flevel=logging.DEBUG, rotate_size=None, level=logging.INFO, logfile=None, flevel=logging.DEBUG, rotate_size=None,
enable_notify=False): enable_notify=False, consolelog=None):
def __send(*args): def __send(*args):
pass pass
if enable_notify: if enable_notify:
@ -307,3 +307,11 @@ def configure_logger(logger, format='%(asctime)s - %(name)-18s - %(levelname)s -
ch.setLevel(level) ch.setLevel(level)
ch.setFormatter(cformatter) ch.setFormatter(cformatter)
logger.addHandler(ch) logger.addHandler(ch)
if consolelog:
assert type(consolelog) is str
cfh = logging.FileHandler(consolelog)
cfh.setLevel(level)
cfhformatter = ExceptionFormatter(fmt=format, notify=False)
cfh.setFormatter(cfhformatter)
logger.addHandler(cfh)
# for client.printlog