From 77ff57eb725e660960c221b0cdec1f79752665a9 Mon Sep 17 00:00:00 2001 From: System User Date: Thu, 2 Dec 2010 16:42:16 +0100 Subject: [PATCH] Add class for logging in log file --- radicale/log.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 radicale/log.py diff --git a/radicale/log.py b/radicale/log.py new file mode 100644 index 0000000..8c7cc55 --- /dev/null +++ b/radicale/log.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +import sys +import logging + +from radicale import config + +LEVELS = { 'debug': logging.DEBUG, + 'info': logging.INFO, + 'warning': logging.WARNING, + 'error': logging.ERROR, + 'critical': logging.CRITICAL} + +level=LEVELS.get(config.get("logging", "level"), logging.NOTSET) + +logger=logging.getLogger("radicale") +logger.setLevel(level=level) + +handler=logging.FileHandler(config.get("logging", "file")) +handler.setLevel(level=level) + +formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") + +handler.setFormatter(formatter) + +logger.addHandler(handler) + +sys.modules[__name__] = logger \ No newline at end of file