1 # Copyright (C) 2021 Wind River Systems, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 import logging.handlers
22 def get_logger(name=None):
23 # CONFIG_FILE = os.environ.get(
24 # "LOGGING_CONFIG_FILE", "/etc/o2/log.yaml")
25 # if os.path.exists(CONFIG_FILE):
26 # with open(file=CONFIG_FILE, mode='r', encoding="utf-8") as file:
27 # config_yaml = yaml.load(stream=file, Loader=yaml.FullLoader)
28 # logging.config.dictConfig(config=config_yaml)
30 logger = logging.getLogger(name)
31 # override root logger's logging level
32 LOGGING_CONFIG_LEVEL = os.environ.get("LOGGING_CONFIG_LEVEL", None)
33 if LOGGING_CONFIG_LEVEL:
34 logger.setLevel(LOGGING_CONFIG_LEVEL)
38 def configure_logger():
39 CONFIG_FILE = os.environ.get(
40 "LOGGING_CONFIG_FILE", "/etc/o2/log.yaml")
41 if os.path.exists(CONFIG_FILE):
42 with open(file=CONFIG_FILE, mode='r', encoding="utf-8") as file:
43 config_yaml = yaml.load(stream=file, Loader=yaml.FullLoader)
44 logging.config.dictConfig(config=config_yaml)