-
Notifications
You must be signed in to change notification settings - Fork 4
/
log.py
47 lines (40 loc) · 1.15 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
"""
log
~~~
Implements color logger
:author: Feei <[email protected]>
:homepage: https://github.com/wufeifei/cobra
:license: MIT, see LICENSE for more details.
:copyright: Copyright (c) 2018 Feei. All rights reserved
"""
import os
import colorlog
import logging
from logging import handlers
log_path = 'logs'
if os.path.isdir(log_path) is not True:
os.mkdir(log_path, 0o755)
logfile = os.path.join(log_path, 'webmonitor.log')
handler = colorlog.StreamHandler()
formatter = colorlog.ColoredFormatter(
'%(log_color)s%(asctime)s [%(name)s] [%(levelname)s] %(message)s%(reset)s',
datefmt=None,
reset=True,
log_colors={
'DEBUG': 'cyan',
'INFO': 'green',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'red,bg_white',
},
secondary_log_colors={},
style='%'
)
handler.setFormatter(formatter)
file_handler = handlers.RotatingFileHandler(logfile, maxBytes=(1048576 * 5), backupCount=7)
file_handler.setFormatter(formatter)
logger = colorlog.getLogger('WebpageMonitor')
logger.addHandler(handler)
logger.addHandler(file_handler)
logger.setLevel(logging.INFO)