mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2024-11-12 16:40:26 +00:00
Log to file only if the file exists
If LOG_FILE config option contained invalid file, pdns admin wouldn't start. Also, it wasn't possible to log only to stdout/stderr correctly, because setting the log file to /dev/stdout would double the logs messages as the pdns admin is already logging to the stderr.
This commit is contained in:
parent
59e91ec7b9
commit
444be2c060
@ -27,18 +27,21 @@ class logger(object):
|
|||||||
# set request requests module log level
|
# set request requests module log level
|
||||||
logging.getLogger("requests").setLevel(logging.CRITICAL)
|
logging.getLogger("requests").setLevel(logging.CRITICAL)
|
||||||
|
|
||||||
# define handler to log into file
|
if self.logfile and os.path.isfile(self.logfile):
|
||||||
file_log_handler = logging.FileHandler(self.logfile)
|
# define handler to log into file
|
||||||
logger.addHandler(file_log_handler)
|
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
|
# define handler to log into console
|
||||||
stderr_log_handler = logging.StreamHandler()
|
stderr_log_handler = logging.StreamHandler()
|
||||||
logger.addHandler(stderr_log_handler)
|
logger.addHandler(stderr_log_handler)
|
||||||
|
|
||||||
# define logging format for file and console
|
# define logging format for console
|
||||||
file_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
||||||
console_formatter = logging.Formatter('[%(levelname)s] %(message)s')
|
console_formatter = logging.Formatter('[%(levelname)s] %(message)s')
|
||||||
file_log_handler.setFormatter(file_formatter)
|
|
||||||
stderr_log_handler.setFormatter(console_formatter)
|
stderr_log_handler.setFormatter(console_formatter)
|
||||||
|
|
||||||
return logging.getLogger(self.name)
|
return logging.getLogger(self.name)
|
@ -14,8 +14,8 @@ TIMEOUT = 10
|
|||||||
# LOG CONFIG
|
# LOG CONFIG
|
||||||
LOG_LEVEL = 'DEBUG'
|
LOG_LEVEL = 'DEBUG'
|
||||||
LOG_FILE = 'logfile.log'
|
LOG_FILE = 'logfile.log'
|
||||||
# For Docker, set the following
|
# For Docker, leave empty string
|
||||||
#LOG_FILE = '/dev/stdout'
|
#LOG_FILE = ''
|
||||||
|
|
||||||
# Upload
|
# Upload
|
||||||
UPLOAD_DIR = os.path.join(basedir, 'upload')
|
UPLOAD_DIR = os.path.join(basedir, 'upload')
|
||||||
|
Loading…
Reference in New Issue
Block a user