From e9c6268c1acd772942d83f897a8701489feb794f Mon Sep 17 00:00:00 2001 From: root Date: Wed, 30 Dec 2015 19:27:28 +0530 Subject: [PATCH 1/9] PXPSE-422-handled to log actions as a seperate log file for each packs --- st2actions/conf/logging.conf | 8 ++++---- st2actions/st2actions/runners/pythonrunner.py | 13 ++++--------- st2common/st2common/logging/handlers.py | 4 +++- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/st2actions/conf/logging.conf b/st2actions/conf/logging.conf index 949b1fffa8..f4db1d5e8f 100644 --- a/st2actions/conf/logging.conf +++ b/st2actions/conf/logging.conf @@ -21,13 +21,13 @@ args=(sys.stdout,) class=st2common.log.FormatNamedFileHandler level=INFO formatter=verboseConsoleFormatter -args=('logs/st2actionrunner.{pid}.log',) +args=('/var/log/st2/st2actionrunner.{pack}.log',) [handler_auditHandler] class=st2common.log.FormatNamedFileHandler level=AUDIT formatter=jsonFormatter -args=('logs/st2actionrunner.{pid}.audit.log',) +args=('/var/log/st2/st2actionrunner.{pack}.audit.log',) [formatter_simpleConsoleFormatter] class=st2common.logging.formatters.ConsoleLogFormatter @@ -36,7 +36,7 @@ datefmt= [formatter_verboseConsoleFormatter] class=st2common.logging.formatters.ConsoleLogFormatter -format=%(asctime)s %(thread)s %(levelname)s %(module)s [-] %(message)s +format=%(asctime)s %(process)d %(thread)s %(levelname)s %(module)s [-] %(message)s datefmt= [formatter_gelfFormatter] @@ -45,4 +45,4 @@ format=%(message)s [formatter_jsonFormatter] class=pythonjsonlogger.jsonlogger.JsonFormatter -format=%(asctime) %(thread) %(levelname) %(module) %(message) +format=%(asctime) %(process)d %(thread) %(levelname) %(module) %(message) diff --git a/st2actions/st2actions/runners/pythonrunner.py b/st2actions/st2actions/runners/pythonrunner.py index 66da0f8d35..3de1d807aa 100644 --- a/st2actions/st2actions/runners/pythonrunner.py +++ b/st2actions/st2actions/runners/pythonrunner.py @@ -18,14 +18,16 @@ import abc import json import uuid +import logging +import logging.config import logging as stdlib_logging import six from eventlet.green import subprocess from st2actions.runners import ActionRunner +from st2actions import config as action_config from st2common.util.green.shell import run_command -from st2common import log as logging from st2common.constants.action import ACTION_OUTPUT_RESULT_DELIMITER from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED from st2common.constants.action import LIVEACTION_STATUS_FAILED @@ -84,17 +86,10 @@ def _set_up_logger(self): Set up a logger which logs all the messages with level DEBUG and above to stderr. """ + logging.config.fileConfig(action_config.get_logging_config_path()) logger_name = 'actions.python.%s' % (self.__class__.__name__) logger = logging.getLogger(logger_name) - console = stdlib_logging.StreamHandler() - console.setLevel(stdlib_logging.DEBUG) - - formatter = stdlib_logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') - console.setFormatter(formatter) - logger.addHandler(console) - logger.setLevel(stdlib_logging.DEBUG) - return logger diff --git a/st2common/st2common/logging/handlers.py b/st2common/st2common/logging/handlers.py index ca8beb5521..70f8e71feb 100644 --- a/st2common/st2common/logging/handlers.py +++ b/st2common/st2common/logging/handlers.py @@ -17,6 +17,7 @@ import socket import time import logging +import sys from oslo_config import cfg @@ -37,7 +38,8 @@ def __init__(self, filename, mode='a', maxBytes=0, backupCount=0, encoding=None, format_values = { 'timestamp': timestamp, 'ts': isotime_str, - 'pid': pid + 'pid': pid, + 'pack': os.path.abspath(os.path.dirname(sys.argv[2])).split('/')[-2] } filename = filename.format(**format_values) super(FormatNamedFileHandler, self).__init__(filename, mode=mode, maxBytes=maxBytes, From d12faf83ca7106524f7ca95c2e01fc8823e8aad7 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 30 Dec 2015 19:41:58 +0530 Subject: [PATCH 2/9] PXPSE-422 : updated the logging.conf --- st2actions/conf/logging.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/st2actions/conf/logging.conf b/st2actions/conf/logging.conf index f4db1d5e8f..62ccd6486f 100644 --- a/st2actions/conf/logging.conf +++ b/st2actions/conf/logging.conf @@ -21,13 +21,13 @@ args=(sys.stdout,) class=st2common.log.FormatNamedFileHandler level=INFO formatter=verboseConsoleFormatter -args=('/var/log/st2/st2actionrunner.{pack}.log',) +args=('logs/st2actionrunner.{pack}.log',) [handler_auditHandler] class=st2common.log.FormatNamedFileHandler level=AUDIT formatter=jsonFormatter -args=('/var/log/st2/st2actionrunner.{pack}.audit.log',) +args=('logs/st2actionrunner.{pack}.audit.log',) [formatter_simpleConsoleFormatter] class=st2common.logging.formatters.ConsoleLogFormatter From a27b7d2725719a52fbe4905d577c58bfe78309e2 Mon Sep 17 00:00:00 2001 From: msheriff Date: Wed, 6 Jan 2016 19:15:33 +0530 Subject: [PATCH 3/9] removing the import logging statement --- st2actions/st2actions/runners/pythonrunner.py | 1 - 1 file changed, 1 deletion(-) diff --git a/st2actions/st2actions/runners/pythonrunner.py b/st2actions/st2actions/runners/pythonrunner.py index 3de1d807aa..43045064a1 100644 --- a/st2actions/st2actions/runners/pythonrunner.py +++ b/st2actions/st2actions/runners/pythonrunner.py @@ -18,7 +18,6 @@ import abc import json import uuid -import logging import logging.config import logging as stdlib_logging From 300b868db62c4e95d7ec75ac7b7a6e4005b173c8 Mon Sep 17 00:00:00 2001 From: msheriff Date: Tue, 12 Jan 2016 17:47:05 +0530 Subject: [PATCH 4/9] PXPSE-422: updated the pythonrunner to get logging from /etc/st2actions/logging.conf --- st2actions/st2actions/runners/pythonrunner.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/st2actions/st2actions/runners/pythonrunner.py b/st2actions/st2actions/runners/pythonrunner.py index 43045064a1..9bcc326180 100644 --- a/st2actions/st2actions/runners/pythonrunner.py +++ b/st2actions/st2actions/runners/pythonrunner.py @@ -19,13 +19,11 @@ import json import uuid import logging.config -import logging as stdlib_logging import six from eventlet.green import subprocess from st2actions.runners import ActionRunner -from st2actions import config as action_config from st2common.util.green.shell import run_command from st2common.constants.action import ACTION_OUTPUT_RESULT_DELIMITER from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED @@ -85,7 +83,7 @@ def _set_up_logger(self): Set up a logger which logs all the messages with level DEBUG and above to stderr. """ - logging.config.fileConfig(action_config.get_logging_config_path()) + logging.config.fileConfig('/etc/st2actions/logging.conf') logger_name = 'actions.python.%s' % (self.__class__.__name__) logger = logging.getLogger(logger_name) From 7adcbd3902869525cfe48ac689de3dd64f6bfc52 Mon Sep 17 00:00:00 2001 From: msheriff Date: Tue, 12 Jan 2016 18:18:02 +0530 Subject: [PATCH 5/9] PXPSE-422:updated pythonrunner.py --- st2actions/st2actions/runners/pythonrunner.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/st2actions/st2actions/runners/pythonrunner.py b/st2actions/st2actions/runners/pythonrunner.py index 9bcc326180..625e3f996d 100644 --- a/st2actions/st2actions/runners/pythonrunner.py +++ b/st2actions/st2actions/runners/pythonrunner.py @@ -24,6 +24,7 @@ from eventlet.green import subprocess from st2actions.runners import ActionRunner +from st2actions import config as action_config from st2common.util.green.shell import run_command from st2common.constants.action import ACTION_OUTPUT_RESULT_DELIMITER from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED @@ -83,7 +84,7 @@ def _set_up_logger(self): Set up a logger which logs all the messages with level DEBUG and above to stderr. """ - logging.config.fileConfig('/etc/st2actions/logging.conf') + logging.config.fileConfig(action_config.get_logging_config_path()) logger_name = 'actions.python.%s' % (self.__class__.__name__) logger = logging.getLogger(logger_name) From 869f1c30964ac1e70549b4344a9c30d5138f205f Mon Sep 17 00:00:00 2001 From: msheriff Date: Tue, 12 Jan 2016 18:45:23 +0530 Subject: [PATCH 6/9] PXPSE-422:updated pythonRunner and handled indentation --- st2actions/st2actions/runners/pythonrunner.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/st2actions/st2actions/runners/pythonrunner.py b/st2actions/st2actions/runners/pythonrunner.py index 625e3f996d..131d9eaaa3 100644 --- a/st2actions/st2actions/runners/pythonrunner.py +++ b/st2actions/st2actions/runners/pythonrunner.py @@ -24,7 +24,6 @@ from eventlet.green import subprocess from st2actions.runners import ActionRunner -from st2actions import config as action_config from st2common.util.green.shell import run_command from st2common.constants.action import ACTION_OUTPUT_RESULT_DELIMITER from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED @@ -81,13 +80,14 @@ def run(self, **kwargs): def _set_up_logger(self): """ - Set up a logger which logs all the messages with level DEBUG + Set up a logger which logs all the messages with level INFO and above to stderr. """ - logging.config.fileConfig(action_config.get_logging_config_path()) + from st2actions import config as action_config + logging.config.fileConfig(action_config.get_logging_config_path()) logger_name = 'actions.python.%s' % (self.__class__.__name__) logger = logging.getLogger(logger_name) - + return logger From d85ba3c0b3d3f41506b19e27f748663f12ddebb1 Mon Sep 17 00:00:00 2001 From: msheriff Date: Wed, 13 Jan 2016 13:43:47 +0530 Subject: [PATCH 7/9] story/MAS/PXPSE-422-create-log-file-for-pack-actio --- st2actions/st2actions/runners/pythonrunner.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/st2actions/st2actions/runners/pythonrunner.py b/st2actions/st2actions/runners/pythonrunner.py index 131d9eaaa3..9b788b3486 100644 --- a/st2actions/st2actions/runners/pythonrunner.py +++ b/st2actions/st2actions/runners/pythonrunner.py @@ -83,11 +83,11 @@ def _set_up_logger(self): Set up a logger which logs all the messages with level INFO and above to stderr. """ - from st2actions import config as action_config - logging.config.fileConfig(action_config.get_logging_config_path()) + config_path = os.path.join(BASE_DIR, '../../conf/logging.conf') + logging.config.fileConfig(config_path, + disable_existing_loggers=False) logger_name = 'actions.python.%s' % (self.__class__.__name__) logger = logging.getLogger(logger_name) - return logger From 93c14e4aadc7f87298d8c21d058af8f7f3ea5a72 Mon Sep 17 00:00:00 2001 From: msheriff Date: Wed, 13 Jan 2016 17:10:33 +0530 Subject: [PATCH 8/9] PXPSE-422:Handled code to run take logging.conf from st2 and connect --- st2actions/st2actions/runners/pythonrunner.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/st2actions/st2actions/runners/pythonrunner.py b/st2actions/st2actions/runners/pythonrunner.py index 9b788b3486..90d4ae0240 100644 --- a/st2actions/st2actions/runners/pythonrunner.py +++ b/st2actions/st2actions/runners/pythonrunner.py @@ -83,9 +83,12 @@ def _set_up_logger(self): Set up a logger which logs all the messages with level INFO and above to stderr. """ - config_path = os.path.join(BASE_DIR, '../../conf/logging.conf') - logging.config.fileConfig(config_path, - disable_existing_loggers=False) + if '/opt/' in BASE_DIR: + from st2actions import config as action_config + config_path = action_config.get_logging_config_path() + elif '/src/' in BASE_DIR: + config_path = os.path.join(BASE_DIR, '../../conf/logging.conf') + logging.config.fileConfig(config_path, disable_existing_loggers=False) logger_name = 'actions.python.%s' % (self.__class__.__name__) logger = logging.getLogger(logger_name) return logger From e601993c835850e605525063f341785c5393ce63 Mon Sep 17 00:00:00 2001 From: msheriff Date: Wed, 13 Jan 2016 17:43:11 +0530 Subject: [PATCH 9/9] PXPSE-422 --- st2actions/st2actions/runners/pythonrunner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st2actions/st2actions/runners/pythonrunner.py b/st2actions/st2actions/runners/pythonrunner.py index 90d4ae0240..ebf346f70f 100644 --- a/st2actions/st2actions/runners/pythonrunner.py +++ b/st2actions/st2actions/runners/pythonrunner.py @@ -86,7 +86,7 @@ def _set_up_logger(self): if '/opt/' in BASE_DIR: from st2actions import config as action_config config_path = action_config.get_logging_config_path() - elif '/src/' in BASE_DIR: + else: config_path = os.path.join(BASE_DIR, '../../conf/logging.conf') logging.config.fileConfig(config_path, disable_existing_loggers=False) logger_name = 'actions.python.%s' % (self.__class__.__name__)