diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-05-29 19:39:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-29 19:39:40 +0200 |
commit | d40daeaa4d099bfa9afa4ab2d3a217289aa51100 (patch) | |
tree | 32c95826d5e66ebb16c4a8f3d22f9249390820bc /python/vyos | |
parent | d7ae866ec5221b42bc9bea5b40dd7f7c0c4d78bd (diff) | |
parent | 5f4335042cf40bf4bf18294706cce0b3a2fd5907 (diff) | |
download | vyos-1x-d40daeaa4d099bfa9afa4ab2d3a217289aa51100.tar.gz vyos-1x-d40daeaa4d099bfa9afa4ab2d3a217289aa51100.zip |
Merge pull request #439 from thomas-mangin/T2088-explicit-airbag
airbag :T2088: make airbag explicit
Diffstat (limited to 'python/vyos')
-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 |