diff options
author | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-12 21:46:57 +0100 |
---|---|---|
committer | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-13 09:56:58 +0100 |
commit | 0263828ce22716446ae5fecb6d223917ee674ee7 (patch) | |
tree | fdf57f6dcbbf97129a3f063adaaf76a7e2818a37 | |
parent | 468a109e058b8b5e2d5b4db11ecab23d73c802fb (diff) | |
download | vyos-1x-0263828ce22716446ae5fecb6d223917ee674ee7.tar.gz vyos-1x-0263828ce22716446ae5fecb6d223917ee674ee7.zip |
cmd: T2226: add the a full log of all commands
-rw-r--r-- | python/vyos/util.py | 19 |
1 files changed, 18 insertions, 1 deletions
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} |