mirror of
https://github.com/Kozea/Radicale.git
synced 2025-06-26 16:45:52 +00:00
Improve error handling
* Check the configuration file for errors (check option names and basic type checking). * Perform basic type checking on command line arguments. * Only print stack traces in debug mode. * Include much more information in error messages (e.g. include the path of invalid files). * Send Bad Request to clients for invalid XML requests or iCalendar data. * Change the log level of some messages.
This commit is contained in:
parent
824835bcd4
commit
c9664137a5
8 changed files with 362 additions and 184 deletions
|
@ -38,6 +38,12 @@ def configure_from_file(logger, filename, debug):
|
|||
return logger
|
||||
|
||||
|
||||
class RemoveTracebackFilter(logging.Filter):
|
||||
def filter(self, record):
|
||||
record.exc_info = None
|
||||
return True
|
||||
|
||||
|
||||
def start(name="radicale", filename=None, debug=False):
|
||||
"""Start the logging according to the configuration."""
|
||||
logger = logging.getLogger(name)
|
||||
|
@ -53,12 +59,14 @@ def start(name="radicale", filename=None, debug=False):
|
|||
# Default configuration, standard output
|
||||
if filename:
|
||||
logger.warning(
|
||||
"Logging configuration file '%s' not found, using stderr." %
|
||||
filename)
|
||||
"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:
|
||||
logger.setLevel(logging.DEBUG)
|
||||
else:
|
||||
logger.addFilter(RemoveTracebackFilter())
|
||||
return logger
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue