forked from Sylhaf/Slash-Dolistripe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_logging.py
49 lines (35 loc) · 1.37 KB
/
app_logging.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
from distutils.debug import DEBUG
import logging
from logging.handlers import RotatingFileHandler
global logger_name
logger_name = "slash-dolistripe"
__is_init__ = False
def init() :
global __is_init__
if __is_init__ :
return
#create log folder at execution path"
import os
if not os.path.exists('logs'):
os.makedirs('logs')
# Create a custom logger
logger = logging.getLogger(logger_name)
#TODO create Categories here
# of this style : logger = logging.getLogger(logger_name + ".persistence")
# Create handlers
c_handler = logging.StreamHandler()
f_handler = RotatingFileHandler('logs/slash-dolistripe.log',encoding = "UTF-8",backupCount=5,maxBytes=20000000) # 2mo per log
c_handler.setLevel(logging.DEBUG)
f_handler.setLevel(logging.DEBUG)
f_handler.doRollover()
# Create formatters and add it to handlers
c_format = logging.Formatter('[%(asctime)s] - %(name)s - %(levelname)s - %(message)s')
f_format = logging.Formatter('[%(asctime)s] - %(name)s - %(levelname)s - %(message)s')
c_handler.setFormatter(c_format)
f_handler.setFormatter(f_format)
# Add handlers to the logger
logger.addHandler(c_handler)
logger.addHandler(f_handler)
logger.setLevel(logging.DEBUG)
logger.debug("logging engine started")
__is_init__ = True