diff options
author | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-05-29 06:37:00 +0100 |
---|---|---|
committer | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-05-29 06:37:00 +0100 |
commit | 5f4335042cf40bf4bf18294706cce0b3a2fd5907 (patch) | |
tree | 260f4c2be93f2f59846982533cd47051d7ea5ec8 /python/vyos/airbag.py | |
parent | 073b2a75f19d3af942e78ae44e2d96162648f844 (diff) | |
download | vyos-1x-5f4335042cf40bf4bf18294706cce0b3a2fd5907.tar.gz vyos-1x-5f4335042cf40bf4bf18294706cce0b3a2fd5907.zip |
airbag: T2088: explicit enabling of the feature
airbag must now be explicitly installed.
the patch also allow to fully disables the installation of the logging
code at setup (and not just installing and doing nothing)
Diffstat (limited to 'python/vyos/airbag.py')
-rw-r--r-- | python/vyos/airbag.py | 36 |
1 files changed, 10 insertions, 26 deletions
diff --git a/python/vyos/airbag.py b/python/vyos/airbag.py index b7838d8a2..510ab7f46 100644 --- a/python/vyos/airbag.py +++ b/python/vyos/airbag.py @@ -17,17 +17,20 @@ import sys from datetime import datetime from vyos import debug -from vyos.config import Config from vyos.logger import syslog from vyos.version import get_version from vyos.version import get_full_version_data -# we allow to disable the extra logging -DISABLE = False + +def enable(log=True): + if log: + _intercepting_logger() + _intercepting_exceptions() _noteworthy = [] + def noteworthy(msg): """ noteworthy can be use to take note things which we may not want to @@ -45,8 +48,6 @@ class _IO(object): def write(self, message): self.std.write(message) - if DISABLE: - return for line in message.split('\n'): s = line.rstrip() if s: @@ -90,14 +91,14 @@ def bug_report(dtype, value, trace): # define an exception handler to be run when an exception # reach the end of __main__ and was not intercepted -def intercepter(dtype, value, trace): +def _intercepter(dtype, value, trace): bug_report(dtype, value, trace) if debug.enabled('developer'): import pdb pdb.pm() -def InterceptingLogger(_singleton=[False]): +def _intercepting_logger(_singleton=[False]): skip = _singleton.pop() _singleton.append(True) if skip: @@ -110,7 +111,7 @@ def InterceptingLogger(_singleton=[False]): # lists as default arguments in function is normally dangerous # as they will keep any modification performed, unless this is # what you want to do (in that case to only run the code once) -def InterceptingException(excepthook,_singleton=[False]): +def _intercepting_exceptions(_singleton=[False]): skip = _singleton.pop() _singleton.append(True) if skip: @@ -118,24 +119,7 @@ def InterceptingException(excepthook,_singleton=[False]): # install the handler to replace the default behaviour # which just prints the exception trace on screen - sys.excepthook = excepthook - - -# Do not attempt the extra logging for operational commands -try: - # This fails during boot - insession = Config().in_session() -except: - # we save info on boot to help debugging - insession = True - - -# Installing the interception, it currently does not work when -# running testing so we are checking that we are on the router -# as otherwise it prevents dpkg-buildpackage to work -if get_version() and insession: - InterceptingLogger() - InterceptingException(intercepter) + sys.excepthook = _intercepter # Messages to print |