-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_helper.py
24 lines (21 loc) · 1.02 KB
/
log_helper.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
import logging.config
import settings as settings
# Using the config file for console logging
logging.config.fileConfig(settings.PROJECT_ROOT + '/log.conf')
# Creating handler for file logging
handler = logging.FileHandler(settings.PROJECT_ROOT + '/bin/logs/info.log')
# Format for file logging
formatter = logging.Formatter('[%(asctime)s][%(threadName)s][%(name)-12s][%(levelname)-2s] : \n \r \t %(message)s \n')
handler.setFormatter(formatter)
# create logger for data adapter
logger = logging.getLogger('archaea')
# assinging the handler
logger.addHandler(handler)
# Creating another handler for error logging which logs to error file
error_handler = logging.FileHandler(settings.PROJECT_ROOT + '/bin/logs/error.log')
error_formatter = logging.Formatter('[%(asctime)s][%(threadName)s][%(name)-12s][%(levelname)-2s] : \n \r \t %(message)s \n')
error_handler.setFormatter(error_formatter)
log_error = logging.getLogger('archaea-error')
log_error.addHandler(error_handler)
# Making the error logger part of logger
logger.error = log_error.error