From 2123d2334dc6cb6964aad8cd9ab3eb6abd7f8635 Mon Sep 17 00:00:00 2001 From: Jerry Date: Thu, 11 Apr 2019 14:55:42 +0800 Subject: [PATCH] imporve logging --- buildbot.py | 31 +++++++++++++++++++------------ utils.py | 10 +++++++--- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/buildbot.py b/buildbot.py index e95ebd3..d4e8473 100755 --- a/buildbot.py +++ b/buildbot.py @@ -65,13 +65,19 @@ class jobsManager: self.pkgconfigs = None self.last_updatecheck = 0.0 self.idle = False + @property + def jobs(self): + return \ + { + 'build_jobs': self.__buildjobs, + 'upload_jobs': self.__uploadjobs, + 'current_job': self.__curr_job + } def __repr__(self): ret = "jobsManager(" for myproperty in ( - '_jobsManager__buildjobs', - '_jobsManager__uploadjobs', - '_jobsManager__curr_job', - 'pkgconfigs', 'last_updatecheck', 'idle' + 'jobs', 'pkgconfigs', + 'last_updatecheck', 'idle' ): ret += f'{myproperty}={getattr(self, myproperty, None)},' ret += ')' @@ -130,7 +136,7 @@ class jobsManager: self.__buildjobs.append(job) def __get_job(self): if self.__curr_job: - logger.error(f'Job {self.__curr_job} failed') + logger.error(f'Job {self.__curr_job} failed. Correct the error and rebuild') self.__finish_job(self.__curr_job, force=True) return self.__get_job() jobs = self.__buildjobs @@ -169,14 +175,12 @@ class jobsManager: fpath.name.endswith(PKG_SIG_SUFFIX)): fpath.unlink() def __sign(self, job): + logger.info('signing in %s %s', job.pkgconfig.dirname, job.arch) cwd = REPO_ROOT / job.pkgconfig.dirname for fpath in cwd.iterdir(): if fpath.name.endswith(PKG_SUFFIX): bash(f'{GPG_SIGN_CMD} {fpath.name}', cwd=cwd) def __upload(self, job): - ''' - wip - ''' suc = True cwd = REPO_ROOT / job.pkgconfig.dirname f_to_upload = list() @@ -352,7 +356,10 @@ updmgr = updateManager() def info(): - return (str(jobsmgr)) + ret = str(jobsmgr) + ret += '\nhuman-readable:\n' + ret += "".join([f"{k} = {jobsmgr.jobs[k]}\n" for k in jobsmgr.jobs]) + ret += f"idle: {jobsmgr.idle}" def rebuild_package(pkgdirname, clean=False): return jobsmgr.rebuild_package(pkgdirname, clean=clean) @@ -365,9 +372,9 @@ def clean_all(): def run(funcname, args=list(), kwargs=dict()): if funcname in ('info', 'rebuild_package', 'clean', 'clean_all'): - logger.info('running: %s %s %s',funcname, args, kwargs) + logger.debug('running: %s %s %s',funcname, args, kwargs) ret = eval(funcname)(*args, **kwargs) - logger.info('done: %s %s',funcname, ret) + logger.info('done: %s %s %s',funcname, args, kwargs) return ret else: logger.error('unexpected: %s %s %s',funcname, args, kwargs) @@ -384,7 +391,7 @@ def __main(): if type(myrecv) is list and len(myrecv) == 3: (funcname, args, kwargs) = myrecv funcname = str(funcname) - logger.info('running: %s %s %s', funcname, args, kwargs) + logger.debug('running: %s %s %s', funcname, args, kwargs) conn.send(run(funcname, args=args, kwargs=kwargs)) except Exception: print_exc_plus() diff --git a/utils.py b/utils.py index d1c3da2..dcf15ed 100644 --- a/utils.py +++ b/utils.py @@ -26,7 +26,7 @@ def background(func): def bash(cmdline, **kwargs): assert type(cmdline) is str - logger.info(f'bash: {cmdline}, kwargs: {kwargs}') + logger.debug(f'bash: {cmdline}, kwargs: {kwargs}') return(run_cmd(['/bin/bash', '-x', '-e', '-c', cmdline], **kwargs)) def mon_bash(cmdline, seconds=60*30, **kwargs): @@ -40,7 +40,7 @@ def nspawn_shell(arch, cmdline, cwd=None, **kwargs): cwd = root / cwd else: cwd = root - logger.info(f'bash_{arch}: {cmdline}, cwd: {cwd}, kwargs: {kwargs}') + logger.debug(f'bash_{arch}: {cmdline}, cwd: {cwd}, kwargs: {kwargs}') if arch in ('aarch64', 'arm64'): command=f'{SHELL_ARM64_ADDITIONAL}; {SHELL_TRAP}; cd \'{cwd}\'; {cmdline}' ret = run_cmd(SHELL_ARCH_ARM64 + [command,], **kwargs) @@ -147,6 +147,10 @@ def run_cmd(cmd, cwd=None, keepalive=False, KEEPALIVE_TIMEOUT=30, RUN_CMD_TIMEOU if code != 0: raise subprocess.CalledProcessError(code, cmd, outstr) + if logfile: + logger.debug('run_cmd: logfile written to %s', str(logfile)) + else: + logger.debug('run_cmd: %s, ret = %s', cmd, outstr) return outstr @@ -256,7 +260,7 @@ def format_exc_plus(): return ret def configure_logger(logger, format='%(asctime)s - %(name)-18s - %(levelname)s - %(message)s', - level=logging.INFO, logfile=None, flevel=logging.INFO, rotate_size=None): + level=logging.INFO, logfile=None, flevel=logging.DEBUG, rotate_size=None): class ExceptionFormatter(logging.Formatter): def format(self, record): if record.levelno == 49: