-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.py
More file actions
25 lines (20 loc) · 820 Bytes
/
utils.py
File metadata and controls
25 lines (20 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os
import json
import logging
from datetime import datetime
def load_json(file_name: str):
if isinstance(file_name, str) and file_name.endswith("json"):
with open(file_name, 'r') as file:
data = json.load(file)
else:
raise ValueError("The file path you passed in is not a json file path.")
return data
def init_logger(outputs_dir):
current_time = datetime.now().strftime("%b%d_%H-%M-%S")
os.makedirs(os.path.join(outputs_dir, "logs"), exist_ok=True)
log_path = os.path.join(outputs_dir, "logs", "{}.txt".format(current_time))
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s || %(message)s",
handlers=[logging.StreamHandler(), logging.FileHandler(log_path)],
)