From 4950123a69a37988ec3d45deac0bb8c5b32ce571 Mon Sep 17 00:00:00 2001 From: Osher Date: Mon, 4 Jun 2018 17:34:17 +0300 Subject: [PATCH] QA-392 - Option for all monkey logs to elk --- py/strato/common/log/configurelogging.py | 8 +++++++- py/strato/common/log/machinereadableformatter.py | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/py/strato/common/log/configurelogging.py b/py/strato/common/log/configurelogging.py index 8109557..c13f596 100644 --- a/py/strato/common/log/configurelogging.py +++ b/py/strato/common/log/configurelogging.py @@ -40,6 +40,13 @@ def configureLogging(name, forceDirectory=None, registerConfigurationReloadSigna hostname = subprocess.check_output('/bin/hostname').strip() if registerConfigurationReloadSignal: _configureLoggingSignalHandlers() + if os.environ.get("MONKEY_ELASTIFY"): + logging.info('Passing monkey logs to elk') + from py.strato.tests.monitors.loggerconfig import LogStashLogger + log = LogStashLogger(loggerName="monkey-logs", messageType="monkey-logs", verbose=False) + _log = log.getLogger() + _log.setLevel(logging.INFO) + logging .root.addHandler(_log) logging.info("Logging started for '%(name)s' on '%(hostname)s'", dict( name=name, hostname=hostname)) @@ -60,7 +67,6 @@ def configureLogger(loggerName): outputFilename = "%s__%s" % (_name, loggerName) _configureOutputToFile(logging.getLogger(loggerName), outputFilename) - def addFileHandler(name, path): fileHandler = logging.FileHandler(filename=path) formatter = logging.Formatter( diff --git a/py/strato/common/log/machinereadableformatter.py b/py/strato/common/log/machinereadableformatter.py index 3019061..1c21e9e 100644 --- a/py/strato/common/log/machinereadableformatter.py +++ b/py/strato/common/log/machinereadableformatter.py @@ -1,10 +1,13 @@ import simplejson +import uuid class MachineReadableFormatter: _IGNORED_ATTRIBUTES = set(['relativeCreated', 'msecs', 'message', 'exc_info', 'startColor', 'endColor']) + session_id = uuid.uuid4() def format(self, record): + record.session_id = str(self.session_id) data = dict(record.__dict__) for attribute in self._IGNORED_ATTRIBUTES: if attribute in data: