Adding tmgr_logger for logging 18/9318/1
authorminhac.lee <minhac.lee@samsung.com>
Tue, 18 Oct 2022 23:56:24 +0000 (08:56 +0900)
committerminhac.lee <minhac.lee@samsung.com>
Tue, 18 Oct 2022 23:56:24 +0000 (08:56 +0900)
Issue-Id: AIMLFW-2

Signed-off-by: minhac.lee <minhac.lee@samsung.com>
Change-Id: Ia735446f54d56428a59e8933450ab3ca7c1f4d3c

kfadapter/tmgr_logger.py [new file with mode: 0644]

diff --git a/kfadapter/tmgr_logger.py b/kfadapter/tmgr_logger.py
new file mode 100644 (file)
index 0000000..79877da
--- /dev/null
@@ -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
+