From 0263828ce22716446ae5fecb6d223917ee674ee7 Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Sun, 12 Apr 2020 21:46:57 +0100 Subject: cmd: T2226: add the a full log of all commands --- python/vyos/util.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'python/vyos') diff --git a/python/vyos/util.py b/python/vyos/util.py index 000b13025..14020e2d9 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -35,7 +35,10 @@ def debug(flag): # this is to force all new flags to be registered here to be documented: if flag not in ['developer', 'ifconfig']: return '' - return flag if os.path.isfile(f'/tmp/vyos.{flag}.debug') else '' + for folder in ('/tmp', '/config'): + if os.path.isfile(f'{folder}/vyos.{flag}.debug'): + return flag + return '' def debug_msg(message, flag=''): @@ -46,6 +49,20 @@ def debug_msg(message, flag=''): if debug(flag): print(f'DEBUG/{flag:<6} {message}') + if not debug('developer'): + return + + logfile = '/tmp/full-log' + existed = os.path.exists(logfile) + + with open(logfile, 'a') as f: + f.write(f'DEBUG/{flag:<6} {message}\n') + if not existed: + # at boot the file is created as root:vyattacfg + # at runtime the file is created as user:vyattacfg + # do not use run/cmd to not have a recursive call to this code + os.system(f'chmod g+w {logfile}') + # There is many (too many) ways to run command with python # os.system, subprocess.Popen, subproces.{run,call,check_output} -- cgit v1.2.3