Просмотр исходного кода

Logging to stdout, syslog or file

System User 15 лет назад
Родитель
Сommit
a4024f8183
3 измененных файлов с 14 добавлено и 4 удалено
  1. 4 1
      config
  2. 1 1
      radicale/config.py
  3. 9 2
      radicale/log.py

+ 4 - 1
config

@@ -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

+ 1 - 1
radicale/config.py

@@ -56,7 +56,7 @@ INITIAL_CONFIG = {
     "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",

+ 9 - 2
radicale/log.py

@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 
 import logging, sys
+from logging.handlers import SysLogHandler
 from radicale import config
 
 class log:
@@ -8,8 +9,14 @@ class log:
 		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)