Commit ffc71fcb1cedb219413a3761ea709782be2a8320

Authored by Samir Aguiar
Committed by Christian Herdtweck
1 parent a4f86aa2

log_helper: remove NullHandler class

This class was only necessary for Python 2.6, but as the support
for that version was dropped it's not needed anymore.
oletools/util/log_helper/_null_handler.py deleted
1 -import logging  
2 -  
3 -  
4 -class NullHandler(logging.Handler):  
5 - """  
6 - Log Handler without output  
7 - """  
8 -  
9 - def emit(self, record):  
10 - pass  
oletools/util/log_helper/log_helper.py
@@ -43,7 +43,6 @@ General logging helpers @@ -43,7 +43,6 @@ General logging helpers
43 43
44 from __future__ import print_function 44 from __future__ import print_function
45 from ._json_formatter import JsonFormatter 45 from ._json_formatter import JsonFormatter
46 -from ._null_handler import NullHandler  
47 from ._logger_class import OletoolsLogger 46 from ._logger_class import OletoolsLogger
48 from . import _root_logger_wrapper 47 from . import _root_logger_wrapper
49 import logging 48 import logging
@@ -81,21 +80,13 @@ class LogHelper: @@ -81,21 +80,13 @@ class LogHelper:
81 def get_or_create_silent_logger(self, name=DEFAULT_LOGGER_NAME, level=logging.CRITICAL + 1): 80 def get_or_create_silent_logger(self, name=DEFAULT_LOGGER_NAME, level=logging.CRITICAL + 1):
82 """ 81 """
83 Get a logger or create one if it doesn't exist, setting a NullHandler 82 Get a logger or create one if it doesn't exist, setting a NullHandler
84 - (to avoid printing to the console) as the handler if that's the case. 83 + as the handler (to avoid printing to the console).
85 By default we also use a higher logging level so every message will 84 By default we also use a higher logging level so every message will
86 be ignored. 85 be ignored.
87 This is useful when we don't want to print anything when the logger 86 This is useful when we don't want to print anything when the logger
88 is not configured by the main application. 87 is not configured by the main application.
89 -  
90 - Python 2.7 has logging.NullHandler, but this is necessary for 2.6:  
91 - git pus https://docs.python.org/2.6/library/logging.html#configuring-logging-for-a-library  
92 """ 88 """
93 - if sys.version_info >= (2, 6):  
94 - handler = logging.NullHandler  
95 - else:  
96 - handler = NullHandler  
97 -  
98 - return self._get_or_create_logger(name, level, handler()) 89 + return self._get_or_create_logger(name, level, logging.NullHandler())
99 90
100 def enable_logging(self, use_json, level, log_format=DEFAULT_MESSAGE_FORMAT, stream=None): 91 def enable_logging(self, use_json, level, log_format=DEFAULT_MESSAGE_FORMAT, stream=None):
101 """ called from main after parsing arguments """ 92 """ called from main after parsing arguments """