def logging_done(): """Close all logging file descriptors""" for handler in root_logger.handlers[:]: debug("close logging handler: %s" % handler) handler.close() root_logger.removeHandler(handler)
def setUp(self): """Make a fresh logger for each test function""" super(LoggingMixin, self).setUp() named = getLogger(self.log_name) for handler in root.handlers[:]: root.removeHandler(handler) for handler in named.handlers[:]: named.removeHandler(handler) self.log_handler = LoggingRecorder(level='DEBUG') named.addHandler(self.log_handler)
def toggle_debug(self): #Once remove all the handlers for handler in root.handlers[:]: root.removeHandler(handler) if self.btn_debug.isChecked(): print("!!!") basicConfig( level=DEBUG, #filename='log.txt', format="%(asctime)s %(levelname)s %(message)s") else: basicConfig(level=WARN, format="%(asctime)s %(levelname)s %(message)s")
def log_collection_context(logging_memory_handler, tempdir, prefix, timestamp, output_path=None, creation_dir=None): from logging import root, DEBUG path = get_tar_path(prefix, output_path, timestamp, creation_dir) root.addHandler(logging_memory_handler) root.setLevel(DEBUG) try: yield path finally: with open_archive(path) as archive: root.removeHandler(logging_memory_handler) logging_memory_handler.flush() logging_memory_handler.close() add_directory(archive, tempdir) print("Logs collected successfully to {}".format(path))
def reset_settings(): for handler in root.handlers: root.removeHandler(handler)
def setUpClass(cls): for handler in root.handlers[:]: root.removeHandler(handler) cls.temp_stdout = sys.stdout sys.stdout = StringIO()