Skip to content

Commit

Permalink
Logging to stdout, syslog or file
Browse files Browse the repository at this point in the history
  • Loading branch information
System User committed Feb 22, 2011
1 parent bb7f36f commit a4024f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion config
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ LDAPAppend = ou=users,dc=exmaple,dc=dom
folder = ~/.config/radicale/calendars

[Logging]
# Logging filename
# Logging type
# Value: syslog | file | stdout
type = file
# Logging filename (if needed)
logfile = ~/.config/radicale/radicale.log
# Log facility 10: DEBUG, 20: INFO, 30 WARNING, 40 ERROR, 50 CRITICAL
facility = 50
Expand Down
2 changes: 1 addition & 1 deletion radicale/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"storage": {
"folder": os.path.expanduser("~/.config/radicale/calendars")},
"logging": {
"logfile": os.path.expanduser("~/.config/radicale/radicale.log"),
"type": "syslog",
"facility": 10},
"authLdap": {
"LDAPServer": "127.0.0.1",
Expand Down
11 changes: 9 additions & 2 deletions radicale/log.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
# -*- coding: utf-8 -*-

import logging, sys
from logging.handlers import SysLogHandler
from radicale import config

class log:
def __init__(self):
self.logger=logging.getLogger("radicale")
self.logger.setLevel(config.get("logging", "facility"))

handler=logging.FileHandler(config.get("logging", "logfile"))

loggingType=config.get("logging", "type")
if loggingType == "stdout":
handler=logging.StreamHandler(sys.stdout)
elif loggingType == "file":
handler=logging.FileHandler(config.get("logging", "logfile"))
else:
handler=logging.handlers.SysLogHandler("/dev/log")

formatter = logging.Formatter('%(name)s %(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)

Expand Down

0 comments on commit a4024f8

Please sign in to comment.