-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.py
More file actions
34 lines (30 loc) · 989 Bytes
/
Copy pathlog.py
File metadata and controls
34 lines (30 loc) · 989 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
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import logging
import colorlog
logger = logging.getLogger()
# log
def log(loglevel, log_name):
handler = colorlog.StreamHandler()
handler.setFormatter(
colorlog.ColoredFormatter(
fmt='%(log_color)s[%(levelname)s] [%(threadName)s] [%(asctime)s] [%(filename)s:%(lineno)d] %(message)s',
datefmt="%H:%M:%S",
log_colors={
'DEBUG': 'cyan',
'INFO': 'green',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'red,bg_white',
},
)
)
log_name += '.log'
f = open("log/" + log_name, 'a+')
handler2 = logging.StreamHandler(f)
formatter = logging.Formatter(
"[%(levelname)s] [%(threadName)s] [%(asctime)s] [%(filename)s:%(lineno)d] %(message)s")
handler2.setFormatter(formatter)
logger.addHandler(handler2)
logger.addHandler(handler)
logger.setLevel(loglevel)