diff options
author | chsailakshmi <sailakshmi@aarnanetworks.com> | 2021-08-25 08:03:28 -0400 |
---|---|---|
committer | chsailakshmi <sailakshmi@aarnanetworks.com> | 2021-08-25 08:04:40 -0400 |
commit | 6b6f2360e4e60d681a5ba0fc05477f9ac9bea051 (patch) | |
tree | b8ff309197f22e3d1bc3dc6dc5b53e7ce40851bc | |
parent | c82f01edbc45dc307af8ab271ccaba08da82b5fc (diff) |
CCSDK-3435 cds py executor log persistence
Change-Id: If83db093e3b331a7f2f45435648aad142a2f78d5
Signed-off-by: chsailakshmi <sailakshmi@aarnanetworks.com>
Issue-ID: CCSDK-3435
-rw-r--r-- | ms/logging.yaml | 9 | ||||
-rw-r--r-- | ms/py-executor/server.py | 27 |
2 files changed, 30 insertions, 6 deletions
diff --git a/ms/logging.yaml b/ms/logging.yaml index 3a31ca85c..914e261b0 100644 --- a/ms/logging.yaml +++ b/ms/logging.yaml @@ -11,4 +11,11 @@ formatters: standard: format: '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s ' - datefmt: "%Y-%m-%d %H:%M:%S"
\ No newline at end of file + datefmt: "%Y-%m-%d %H:%M:%S" + default: + format: '%(asctime)s - %(name)s - %(threadName)s - %(levelname)s - %(message)s' + +loglevel: info +logfilesize: 1048576 +rollovercount: 5 + diff --git a/ms/py-executor/server.py b/ms/py-executor/server.py index 7f6537011..2420344ee 100644 --- a/ms/py-executor/server.py +++ b/ms/py-executor/server.py @@ -18,6 +18,7 @@ import logging import os import time +import yaml from builtins import KeyboardInterrupt from concurrent import futures from pathlib import Path, PurePath @@ -96,13 +97,29 @@ if __name__ == '__main__': config_file = str(os.path.expanduser(Path(supplied_configuration_file or default_configuration_file))) configuration = ScriptExecutorConfiguration(config_file) - logging_formater = '%(asctime)s - %(name)s - %(threadName)s - %(levelname)s - %(message)s' - logging.basicConfig(filename=configuration.script_executor_property('logFile'), - level=logging.DEBUG, + log_file_name = configuration.script_executor_property('logFile') + log_file = os.path.join(os.path.dirname(os.path.abspath(os.path.dirname(__file__))), "logging.yaml") + print(log_file) + with open(log_file) as log: + log_config = yaml.safe_load(log) + print(log_config) + logging_formater = log_config["formatters"]["default"]["format"] + print(log_config["loglevel"]) + if log_config["loglevel"] == "debug": + loglevel = logging.DEBUG + elif log_config["loglevel"] == "info": + loglevel = logging.INFO + elif log_config["loglevel"] == "error": + loglevel = logging.ERROR + logging.basicConfig(filename=log_file_name, + level=loglevel, format=logging_formater) - console = logging.StreamHandler() - console.setLevel(logging.INFO) + console = logging.handlers.RotatingFileHandler(log_file_name, maxBytes=log_config["logfilesize"], + backupCount=log_config["rollovercount"]) + + console.setLevel(loglevel) formatter = logging.Formatter(logging_formater) console.setFormatter(formatter) logging.getLogger('').addHandler(console) serve(configuration) + |