forked from huaisha1224/jd-assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.py
30 lines (22 loc) · 829 Bytes
/
log.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
30
#!/usr/bin/env python
# -*- encoding=utf8 -*-
import logging
import logging.handlers
import os
from time import strftime
LOG_FILENAME = strftime("logs\jd-assistant_%Y_%m_%d_%H.log")
logger = logging.getLogger()
def set_logger():
path = os.path.dirname(os.getcwd()+ '\\logs\\') # 判断日志目录
if not os.path.exists(path):
os.makedirs(path)
logger.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
file_handler = logging.handlers.RotatingFileHandler(
LOG_FILENAME, maxBytes=10485760, backupCount=5, encoding="utf-8")
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
set_logger()