fail when logging config file is not found
This commit is contained in:
parent
1812aeb238
commit
5d27265d5c
@ -24,7 +24,6 @@ http://docs.python.org/library/logging.config.html
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import os
|
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -47,26 +46,30 @@ class RemoveTracebackFilter(logging.Filter):
|
|||||||
def start(name="radicale", filename=None, debug=False):
|
def start(name="radicale", filename=None, debug=False):
|
||||||
"""Start the logging according to the configuration."""
|
"""Start the logging according to the configuration."""
|
||||||
logger = logging.getLogger(name)
|
logger = logging.getLogger(name)
|
||||||
if filename and os.path.exists(filename):
|
|
||||||
# Configuration taken from file
|
|
||||||
configure_from_file(logger, filename, debug)
|
|
||||||
# Reload config on SIGHUP (UNIX only)
|
|
||||||
if hasattr(signal, "SIGHUP"):
|
|
||||||
def handler(signum, frame):
|
|
||||||
configure_from_file(logger, filename, debug)
|
|
||||||
signal.signal(signal.SIGHUP, handler)
|
|
||||||
else:
|
|
||||||
# Default configuration, standard output
|
|
||||||
if filename:
|
|
||||||
logger.warning(
|
|
||||||
"WARNING: Logging configuration file %r not found, using "
|
|
||||||
"stderr" % filename)
|
|
||||||
handler = logging.StreamHandler(sys.stderr)
|
|
||||||
handler.setFormatter(
|
|
||||||
logging.Formatter("[%(thread)x] %(levelname)s: %(message)s"))
|
|
||||||
logger.addHandler(handler)
|
|
||||||
if debug:
|
if debug:
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
else:
|
else:
|
||||||
logger.addFilter(RemoveTracebackFilter())
|
logger.addFilter(RemoveTracebackFilter())
|
||||||
|
if filename:
|
||||||
|
# Configuration taken from file
|
||||||
|
try:
|
||||||
|
configure_from_file(logger, filename, debug)
|
||||||
|
except Exception as e:
|
||||||
|
raise RuntimeError("Failed to load logging configuration file %r: "
|
||||||
|
"%s" % (filename, e)) from e
|
||||||
|
# Reload config on SIGHUP (UNIX only)
|
||||||
|
if hasattr(signal, "SIGHUP"):
|
||||||
|
def handler(signum, frame):
|
||||||
|
try:
|
||||||
|
configure_from_file(logger, filename, debug)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("Failed to reload logging configuration file "
|
||||||
|
"%r: %s", filename, e, exc_info=True)
|
||||||
|
signal.signal(signal.SIGHUP, handler)
|
||||||
|
else:
|
||||||
|
# Default configuration, standard output
|
||||||
|
handler = logging.StreamHandler(sys.stderr)
|
||||||
|
handler.setFormatter(
|
||||||
|
logging.Formatter("[%(thread)x] %(levelname)s: %(message)s"))
|
||||||
|
logger.addHandler(handler)
|
||||||
return logger
|
return logger
|
||||||
|
Loading…
Reference in New Issue
Block a user