Merge pull request #132 from pschiffe/master

Log to file only if the file exists
This commit is contained in:
Khanh Ngo 2016-09-05 09:22:12 +07:00 committed by GitHub
commit 39fab003f2
2 changed files with 11 additions and 8 deletions

View File

@ -27,18 +27,21 @@ class logger(object):
# set request requests module log level
logging.getLogger("requests").setLevel(logging.CRITICAL)
# define handler to log into file
file_log_handler = logging.FileHandler(self.logfile)
logger.addHandler(file_log_handler)
if self.logfile:
# define handler to log into file
file_log_handler = logging.FileHandler(self.logfile)
logger.addHandler(file_log_handler)
# define logging format for file
file_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_log_handler.setFormatter(file_formatter)
# define handler to log into console
stderr_log_handler = logging.StreamHandler()
logger.addHandler(stderr_log_handler)
# define logging format for file and console
file_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# define logging format for console
console_formatter = logging.Formatter('[%(levelname)s] %(message)s')
file_log_handler.setFormatter(file_formatter)
stderr_log_handler.setFormatter(console_formatter)
return logging.getLogger(self.name)

View File

@ -14,8 +14,8 @@ TIMEOUT = 10
# LOG CONFIG
LOG_LEVEL = 'DEBUG'
LOG_FILE = 'logfile.log'
# For Docker, set the following
#LOG_FILE = '/dev/stdout'
# For Docker, leave empty string
#LOG_FILE = ''
# Upload
UPLOAD_DIR = os.path.join(basedir, 'upload')