commit da7ff110d28ab581b162b5a7a29acdce0f459a6c
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Fri Apr 12 12:20:02 2013 +0200
Logs: add method disable_logging
This commit adds a new method that can be used to remove all the
handlers in the logging system. This effectively disables the logging
functionality and any log messages will be discarded.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
lnst/Common/Logs.py | 26 +++++++++++++++++++-------
1 files changed, 19 insertions(+), 7 deletions(-)
---
diff --git a/lnst/Common/Logs.py b/lnst/Common/Logs.py
index f00082d..032a4af 100644
--- a/lnst/Common/Logs.py
+++ b/lnst/Common/Logs.py
@@ -78,6 +78,7 @@ class MultilineFormater(Formatter):
class LoggingCtl:
log_folder = ""
formatter = None
+ display_handler = None
recipe_handlers = (None,None)
recipe_log_path = ""
slaves = {}
@@ -101,19 +102,19 @@ class LoggingCtl:
#the display_handler will display logs in the terminal
- display_handler = logging.StreamHandler(sys.stdout)
- display_handler.setFormatter(self.formatter)
+ self.display_handler = logging.StreamHandler(sys.stdout)
+ self.display_handler.setFormatter(self.formatter)
if not debug:
- display_handler.setLevel(logging.INFO)
+ self.display_handler.setLevel(logging.INFO)
else:
if debug == 1:
- display_handler.setLevel(logging.DEBUG)
+ self.display_handler.setLevel(logging.DEBUG)
else:
- display_handler.setLevel(logging.NOTSET)
+ self.display_handler.setLevel(logging.NOTSET)
logger = logging.getLogger()
logger.setLevel(logging.NOTSET)
- logger.addHandler(display_handler)
+ logger.addHandler(self.display_handler)
def set_recipe(self, recipe_path, clean=True, expand=""):
recipe_name = os.path.splitext(os.path.split(recipe_path)[1])[0]
@@ -162,7 +163,7 @@ class LoggingCtl:
logger.removeHandler(self.slaves[name][0])
logger.removeHandler(self.slaves[name][1])
- del slaves[name]
+ del self.slaves[name]
def set_connection(self, target):
if self.transmit_handler != None:
@@ -181,6 +182,17 @@ class LoggingCtl:
logger.removeHandler(self.transmit_handler)
del self.transmit_handler
+ def disable_logging(self):
+ self.cancel_connection()
+
+ for s in self.slaves.keys():
+ self.remove_slave(s)
+
+ self.unset_recipe()
+ logger = logging.getLogger()
+ logger.removeHandler(self.display_handler)
+ self.display_handler = None
+
def _clean_folder(self, path):
try:
shutil.rmtree(path)
Show replies by date