-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger_config.py
47 lines (43 loc) · 1.18 KB
/
logger_config.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
import logging.config
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
LOGGER = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': ("[%(asctime)s] %(levelname)s "
"[%(name)s:%(lineno)s] %(message)s"),
'datefmt': "%d/%b/%Y %H:%M:%S",
},
'simple': {
'format': '%(levelname)s %(message)s',
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'verbose',
'level': 'INFO',
},
'file': {
'class': 'logging.handlers.RotatingFileHandler',
'maxBytes': 1024 * 1024 * 100, # 100 MB
'backupCount': 5,
'filename': 'aws-stream.log',
'formatter': 'verbose',
'level': logging.DEBUG,
},
},
'root': {
'level': 'DEBUG',
'handlers': ['console', 'file']
},
}
def setup_logging():
# Add the log message handler to the logger
LOG_FILENAME = os.path.join(BASE_DIR, 'logs', os.getenv('SCRIPT_NAME', 'aws-stream') + '.log')
LOGGER['handlers']['file']['filename'] = LOG_FILENAME
logging.config.dictConfig(LOGGER)
root = logging.getLogger()
root.setLevel(os.getenv('LOG_LEVEL', logging.INFO))