From: minhac.lee Date: Tue, 18 Oct 2022 23:56:24 +0000 (+0900) Subject: Adding tmgr_logger for logging X-Git-Tag: 1.0.0~21 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=ab23d9d3388e4349ee9ed286c0a0fe23147f5b37;p=aiml-fw%2Fathp%2Ftps%2Fkubeflow-adapter.git Adding tmgr_logger for logging Issue-Id: AIMLFW-2 Signed-off-by: minhac.lee Change-Id: Ia735446f54d56428a59e8933450ab3ca7c1f4d3c --- diff --git a/kfadapter/tmgr_logger.py b/kfadapter/tmgr_logger.py new file mode 100644 index 0000000..79877da --- /dev/null +++ b/kfadapter/tmgr_logger.py @@ -0,0 +1,63 @@ +#!/usr/bin/python3 +# ================================================================================== +# +# Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ================================================================================== +"""tmgr_logger.py +This module is for Initializing Logger Framework +""" + +import logging +import logging.config +import yaml + + +class TMLogger(object):# pylint: disable=too-few-public-methods + """ + This is a class for initiliazing logger configuration for TMLogger + Attributes: None + """ + + def __init__(self, conf_file): + """ + The constructor for TMLogger class. + Parameters:None + """ + + try: + with open(conf_file, 'r') as file: + log_config = yaml.safe_load(file.read()) + logging.config.dictConfig(log_config) + except FileNotFoundError as err: + print("error opening yaml config file") + print(err) + self.LogLevel = log_config["root"]["level"] + self.logger = logging.getLogger(__name__) + + @property + def get_logger(self): + """ + Function for giving logger instance to the caller of the function + Args:None + Returns: + logger: logger handle to be used in other modules + """ + return self.logger + + @property + def get_logLevel(self): + return self.LogLevel +