diff --git a/buildbot.py b/buildbot.py index 7d7a98b..2d45051 100755 --- a/buildbot.py +++ b/buildbot.py @@ -19,7 +19,7 @@ from config import ARCHS, BUILD_ARCHS, BUILD_ARCH_MAPPING, \ MAKEPKG_MAKE_CMD, MAKEPKG_MAKE_CMD_CLEAN, \ GPG_SIGN_CMD, GPG_VERIFY_CMD, UPDATE_INTERVAL, \ 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, \ bash, get_pkg_details_from_name, vercmp, \ @@ -37,7 +37,7 @@ abspath=os.path.dirname(abspath) os.chdir(abspath) 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 if 'systemd-nspawn' in bash('systemd-detect-virt || true'): diff --git a/client.py b/client.py index 80b10e1..4cb9b12 100755 --- a/client.py +++ b/client.py @@ -8,7 +8,8 @@ from multiprocessing.connection import Client from time import sleep 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 @@ -40,36 +41,8 @@ if __name__ == '__main__': from utils import configure_logger configure_logger(logger) def print_log(): - import os, re - abspath=os.path.abspath(__file__) - 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) + import os + os.system(f'tail -f {CONSOLE_LOGFILE}') try: actions = { 'info': 'show buildbot info', diff --git a/config.py b/config.py index 6f83a16..4adbcf2 100644 --- a/config.py +++ b/config.py @@ -62,3 +62,5 @@ UPLOAD_CMD = 'rsync -avPh \"{src}\" repoupload:/srv/repo/buildbot/repo/updates/' GIT_PULL = 'git pull' GIT_RESET_SUBDIR = 'git checkout HEAD -- .' + +CONSOLE_LOGFILE = 'buildbot.log.console' diff --git a/repod.py b/repod.py index 618f6b7..2a8ca04 100755 --- a/repod.py +++ b/repod.py @@ -28,7 +28,7 @@ abspath=os.path.dirname(abspath) os.chdir(abspath) 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: def __init__(self): diff --git a/utils.py b/utils.py index d153328..792f5e5 100644 --- a/utils.py +++ b/utils.py @@ -261,7 +261,7 @@ def format_exc_plus(): def configure_logger(logger, format='%(asctime)s - %(name)-18s - %(levelname)s - %(message)s', level=logging.INFO, logfile=None, flevel=logging.DEBUG, rotate_size=None, - enable_notify=False): + enable_notify=False, consolelog=None): def __send(*args): pass if enable_notify: @@ -307,3 +307,11 @@ def configure_logger(logger, format='%(asctime)s - %(name)-18s - %(levelname)s - ch.setLevel(level) ch.setFormatter(cformatter) 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