-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBaseLogger.py
executable file
·65 lines (40 loc) · 1.87 KB
/
BaseLogger.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
"""Basic logger to support other workers for github profile crawler"""
from config import config_log_file
from logging import INFO, DEBUG, Formatter, getLogger, FileHandler, StreamHandler, shutdown
from sys import stdout
class BaseLogger():
def __init__(self, caller_name="%(module)s", level=None):
if level == None:
level = INFO
log_formatter = Formatter("[%(asctime)s.%(msecs)-3.3d][{}][%(process)d][%(levelname)s] %(message)s".format(caller_name), datefmt="%Y-%m-%d,%H:%M:%S")
self._root_logger = getLogger(caller_name)
self._root_logger.setLevel(level)
self._root_logger.addHandler(self._file_handler(log_formatter))
self._root_logger.addHandler(self._console_handler(log_formatter))
def _file_handler(self, log_formatter):
file_handler = FileHandler(config_log_file)
file_handler.setFormatter(log_formatter)
return file_handler
def _console_handler(self, log_formatter):
console_handler = StreamHandler(stdout)
console_handler.setFormatter(log_formatter)
return console_handler
def _log_critical(self, msg, *args, **kwargs):
self._root_logger.critical(msg, *args, **kwargs)
def _log_error(self, msg, *args, **kwargs):
self._root_logger.error(msg, *args, **kwargs)
def _log_exception(self, msg, *args, **kwargs):
self._root_logger.exception("Exception: {}".format(msg, *args, **kwargs))
def _log_warning(self, msg, *args, **kwargs):
self._root_logger.warning(msg, *args, **kwargs)
def _log_info(self, msg, *args, **kwargs):
self._root_logger.info(msg, *args, **kwargs)
def _log_debug(self, msg, *args, **kwargs):
self._root_logger.debug(msg, *args, **kwargs)
def _close_logger(self):
shutdown()
def main():
pass
if __name__ == '__main__':
main()