Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INDY-1102] Fix Logger setting #555

Merged
merged 1 commit into from
Mar 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions stp_core/common/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,7 @@ def __init__(self, config=None):
self._config = config or getConfig()
self._addTraceToLogging()
self._addDisplayToLogging()

self._handlers = {}
self._format = logging.Formatter(fmt=self._config.logFormat,
style=self._config.logFormatStyle)

if self._config.enableStdOutLogging:
self.enableStdLogging()

logLevel = logging.INFO
if hasattr(self._config, "logLevel"):
logLevel = self._config.logLevel
self.setLogLevel(logLevel)
self.apply_config(self._config)

@staticmethod
def getlogger(name=None):
Expand All @@ -59,6 +48,23 @@ def getlogger(name=None):
def setLogLevel(log_level):
logging.root.setLevel(log_level)

def apply_config(self, config):
assert config

self._config = config
self._handlers = {}
self._clearAllHandlers()
self._format = logging.Formatter(fmt=self._config.logFormat,
style=self._config.logFormatStyle)

if self._config.enableStdOutLogging:
self.enableStdLogging()

logLevel = logging.INFO
if hasattr(self._config, "logLevel"):
logLevel = self._config.logLevel
self.setLogLevel(logLevel)

def enableStdLogging(self):
# only enable if CLI is not
if 'cli' in self._handlers:
Expand Down Expand Up @@ -101,6 +107,10 @@ def _clearHandler(self, typ: str):
if old:
logging.root.removeHandler(old)

def _clearAllHandlers(self):
for hdlr in logging.root.handlers:
logging.root.removeHandler(hdlr)

@staticmethod
def _addTraceToLogging():
logging.addLevelName(TRACE_LOG_LEVEL, "TRACE")
Expand Down