-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlogger_config.py
More file actions
35 lines (28 loc) · 995 Bytes
/
logger_config.py
File metadata and controls
35 lines (28 loc) · 995 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
26
27
28
29
30
31
32
33
34
35
#! /user/bin/evn python
# -*- coding:utf8 -*-
"""
@Author : Lau James
@Contact : LauJames2017@whu.edu.cn
@Project : MVLSTM
@File : logger_config.py
@Time : 19-1-16 下午7:44
@Software : PyCharm
@Copyright: "Copyright (c) 2018 Lau James. All Rights Reserved"
"""
import logging
import time
import os
base_logger = logging.getLogger("tk_logger")
base_logger.setLevel(logging.DEBUG)
curdir = os.path.dirname(os.path.abspath(__file__)).replace('\\', '/')
now_date = time.strftime("%Y_%m_%d")
fh = logging.FileHandler(curdir + '/web_server/logs/%s' % (now_date+'_dl.log'))
# 再创建一个handler,用于输出到控制台
ch = logging.StreamHandler()
# 定义handler的输出格式formatter
formatter = logging.Formatter("%(asctime)s %(pathname)s %(filename)s %(funcName)s %(lineno)s "
"%(levelname)s - %(message)s", "%Y-%m-%d %H:%M:%S")
fh.setFormatter(formatter)
ch.setFormatter(formatter)
base_logger.addHandler(fh)
base_logger.addHandler(ch)