mirror of
https://github.com/Kozea/Radicale.git
synced 2025-06-26 16:45:52 +00:00
Add class for logging in log file
This commit is contained in:
parent
8a86f57304
commit
77ff57eb72
1 changed files with 28 additions and 0 deletions
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…
Add table
Add a link
Reference in a new issue