config.py
899 Bytes
from django.conf import settings
import logging
import sys
# maybe reset files with a variable from settings for the logging
# if (settings.RESETLOGS):
logging.basicConfig(filename='%s/../logs/pyros.log'%(settings.BASE_DIR), format='%(asctime)s : %(module)s -> %(message)s', level=logging.DEBUG)
if (settings.DEBUG):
logging.info('Logger instantiated')
def setupLogger(logger_name, log_file, level=logging.INFO):
l = logging.getLogger(logger_name)
formatter = logging.Formatter('%(filename)s : %(lineno)s -> %(message)s')
fileHandler = logging.FileHandler('%s/../logs/%s.log'%(settings.BASE_DIR, log_file), mode='w')
fileHandler.setFormatter(formatter)
# streamHandler = logging.StreamHandler()
# streamHandler.setFormatter(formatter)
l.setLevel(level)
l.addHandler(fileHandler)
# l.addHandler(streamHandler)
return (logging.getLogger(logger_name))