Skip to content

Commit b37be10

Browse files
author
Yifan Wu
committed
Switch back to logging.yaml and make it optional
1 parent 3d5cfa8 commit b37be10

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

pytextdist/__init__.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22
import logging
33
import logging.config
4-
import json
54

65
__name__ = "pytextdist"
76
__version__ = "0.1.5"
@@ -19,23 +18,24 @@
1918

2019
"""
2120
Set up logging
22-
| Default logging configuration can be edited in logging.json.
21+
| Default logging configuration can be edited in logging.yaml
2322
| You can also bring customized logging modules.
2423
"""
2524

2625
env_key = "LOG_CFG"
2726
value = os.getenv(env_key, None)
2827

2928
init_file_dir = os.path.dirname(os.path.abspath(__file__))
30-
logger_config_json_path = value if value else os.path.join(init_file_dir, "logging.json")
29+
logger_config_yaml_path = value if value else os.path.join(init_file_dir, "logging.yaml")
3130
logger_default_level = logging.INFO
3231

33-
if os.path.exists(logger_config_json_path):
34-
with open(logger_config_json_path, "rb") as f:
35-
try:
36-
config = json.load(f)
37-
except:
38-
config = json.loads(f.read().decode('utf-8'))
39-
logging.config.dictConfig(config)
40-
else:
32+
try:
33+
import yaml
34+
if os.path.exists(logger_config_yaml_path):
35+
with open(logger_config_yaml_path, "rt") as f:
36+
config = yaml.safe_load(f.read())
37+
logging.config.dictConfig(config)
38+
else:
39+
logging.basicConfig(level=logger_default_level)
40+
except:
4141
logging.basicConfig(level=logger_default_level)

pytextdist/logging.json

-1
This file was deleted.

0 commit comments

Comments
 (0)