summaryrefslogtreecommitdiff
path: root/python/vyos/util.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-04-13 14:09:08 +0200
committerGitHub <noreply@github.com>2020-04-13 14:09:08 +0200
commit518626c9cdd4430828d8909a9e2cdb88f3283f97 (patch)
treea80cbb4d46b7b070d42f311bb98076fa7fdec885 /python/vyos/util.py
parent19effc69296911e45e848f96100ff6595571a7df (diff)
parent0263828ce22716446ae5fecb6d223917ee674ee7 (diff)
downloadvyos-1x-518626c9cdd4430828d8909a9e2cdb88f3283f97.tar.gz
vyos-1x-518626c9cdd4430828d8909a9e2cdb88f3283f97.zip
Merge pull request #337 from thomas-mangin/T2226-log
cmd: T2226: add the a full log of all commands
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r--python/vyos/util.py19
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}