-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
29 lines (22 loc) · 804 Bytes
/
logger.py
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
26
27
28
29
import datetime
import logging
import os
from config import Config
def setup_logging():
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
log_filename = f'topic_modeling_{timestamp}.log'
os.makedirs(Config.LOG_DIR, exist_ok=True)
log_path = os.path.join(Config.LOG_DIR, log_filename)
logging.basicConfig(
filename=log_path,
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
console = logging.StreamHandler()
console.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)
return log_path
log_path = setup_logging()
logger = logging.getLogger(__name__)