diff options
author | 2020-05-12 12:56:56 +0100 | |
---|---|---|
committer | 2020-06-05 10:11:06 +0100 | |
commit | 2760519436f78975f16f26c412e842e34b28d624 (patch) | |
tree | 3fb616398002bd4525c10ff8b510bbf5ebadc26f /components/pm-subscription-handler/pmsh_service/mod/__init__.py | |
parent | 5ed9b7d3cad56c6438bca305b6d2931bd320352b (diff) |
[PMSH] Replace own logging implementation with pylog
Signed-off-by: ERIMROB <robertas.rimkus@est.tech>
Issue-ID: DCAEGEN2-2155
Change-Id: I670c4fff8029a73075b651c2afe6237c08cf907c
Diffstat (limited to 'components/pm-subscription-handler/pmsh_service/mod/__init__.py')
-rw-r--r-- | components/pm-subscription-handler/pmsh_service/mod/__init__.py | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/components/pm-subscription-handler/pmsh_service/mod/__init__.py b/components/pm-subscription-handler/pmsh_service/mod/__init__.py index 5c0a5144..316687c0 100644 --- a/components/pm-subscription-handler/pmsh_service/mod/__init__.py +++ b/components/pm-subscription-handler/pmsh_service/mod/__init__.py @@ -15,17 +15,21 @@ # # SPDX-License-Identifier: Apache-2.0 # ============LICENSE_END===================================================== +import logging as logging import os +import pathlib from urllib.parse import quote from connexion import App from flask_sqlalchemy import SQLAlchemy - -import mod.pmsh_logging as logger +from onaplogging import monkey +from onaplogging.mdcContext import MDC +from ruamel.yaml import YAML db = SQLAlchemy() basedir = os.path.abspath(os.path.dirname(__file__)) _connexion_app = None +logger = logging.getLogger('onap_logger') def _get_app(): @@ -43,7 +47,7 @@ def launch_api_server(app_config): def create_app(): - logger.create_loggers(os.getenv('LOGS_PATH')) + create_logger() connex_app = _get_app() app = connex_app.app app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False @@ -53,6 +57,31 @@ def create_app(): return app +def create_logger(): + config_file_path = os.getenv('LOGGER_CONFIG') + update_config(config_file_path) + monkey.patch_loggingYaml() + logging.config.yamlConfig(filepath=config_file_path, + watchDog=os.getenv('DYNAMIC_LOGGER_CONFIG', True)) + old_record = logging.getLogRecordFactory() + + def augment_record(*args, **kwargs): + new_record = old_record(*args, **kwargs) + new_record.mdc = MDC.result() + return new_record + + logging.setLogRecordFactory(augment_record) + + +def update_config(config_file_path): + config_yaml = YAML() + config_file = pathlib.Path(config_file_path) + data = config_yaml.load(config_file) + data['handlers']['onap_log_handler']['filename'] = \ + f'{os.getenv("LOGS_PATH")}/application.log' + config_yaml.dump(data, config_file) + + def get_db_connection_url(): pg_host = os.getenv('PMSH_PG_URL') pg_user = os.getenv('PMSH_PG_USERNAME') |