-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.py
More file actions
46 lines (31 loc) · 1.18 KB
/
logger.py
File metadata and controls
46 lines (31 loc) · 1.18 KB
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
# -*- coding: utf-8 -*-
"""
https://docs.python.org/3/howto/logging-cookbook.html
https://docs.python.org/ko/3/library/logging.handlers.html
"""
# TODO logging.ini 파일로 설정 대체
import logging
from logging.handlers import TimedRotatingFileHandler
from utils import create_folder
from utils.klass.singleton import Singleton
__all__ = (
'Logger'
)
class Logger(metaclass=Singleton):
__slots__ = ["_log"]
def __init__(self):
create_folder("logs")
self._log = logging.getLogger("my")
self._log.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(filename)s - %(lineno)s - %(levelname)s - %(message)s')
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(formatter)
time_log_handler = TimedRotatingFileHandler(filename='./logs/server.log', when='midnight', interval=1,
encoding='utf-8')
time_log_handler.setFormatter(formatter)
time_log_handler.suffix = "%Y%m%d"
self._log.addHandler(time_log_handler)
self._log.addHandler(stream_handler)
@property
def log(self):
return self._log