You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
545 B
Python
25 lines
545 B
Python
import json
|
|
import logging
|
|
import logging.config
|
|
import os
|
|
|
|
|
|
def setup_logging(
|
|
default_path="logging.conf", default_level=logging.INFO, env_key="LOG_CFG"
|
|
):
|
|
"""Setup logging configuration"""
|
|
path = default_path
|
|
value = os.getenv(env_key, None)
|
|
if value:
|
|
path = value
|
|
if os.path.exists(path):
|
|
with open(path, "rt") as f:
|
|
config = json.load(f)
|
|
logging.config.dictConfig(config)
|
|
else:
|
|
logging.basicConfig(level=default_level)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
setup_logging()
|