-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
33 lines (25 loc) · 827 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
30
31
32
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
"""
@file: logger.py
@author: ImKe at 2021/3/29
@email: [email protected]
@feature: #Enter features here
"""
import logging
class Logger(object):
def __init__(self, log_file):
self.logger = logging.getLogger()
self.formatter = logging.Formatter(fmt='[%(asctime)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
self.logger.setLevel(logging.INFO)
self.logger.handlers = []
fh = logging.FileHandler(log_file, mode='w')
fh.setLevel(logging.INFO)
fh.setFormatter(self.formatter)
self.logger.addHandler(fh)
sh = logging.StreamHandler()
sh.setLevel(logging.INFO)
sh.setFormatter(self.formatter)
self.logger.addHandler(sh)
def info(self, text):
self.logger.info(text)