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/mock_smo/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)
32 # override logging level
33 LOGGING_CONFIG_LEVEL = os.environ.get("LOGGING_CONFIG_LEVEL", None)
34 if LOGGING_CONFIG_LEVEL:
35 logger.setLevel(LOGGING_CONFIG_LEVEL)