Add class for logging in log file
This commit is contained in:
parent
8a86f57304
commit
77ff57eb72
28
radicale/log.py
Normal file
28
radicale/log.py
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user