[CalendarServer-changes] [2352]
CalendarServer/branches/users/wsanchez/logging
source_changes at macosforge.org
source_changes at macosforge.org
Fri Apr 25 17:26:51 PDT 2008
Revision: 2352
http://trac.macosforge.org/projects/calendarserver/changeset/2352
Author: wsanchez at apple.com
Date: 2008-04-25 17:26:51 -0700 (Fri, 25 Apr 2008)
Log Message:
-----------
Set log levels in config.
Modified Paths:
--------------
CalendarServer/branches/users/wsanchez/logging/conf/caldavd-test.plist
CalendarServer/branches/users/wsanchez/logging/conf/caldavd.plist
CalendarServer/branches/users/wsanchez/logging/twistedcaldav/config.py
CalendarServer/branches/users/wsanchez/logging/twistedcaldav/test/test_config.py
Modified: CalendarServer/branches/users/wsanchez/logging/conf/caldavd-test.plist
===================================================================
--- CalendarServer/branches/users/wsanchez/logging/conf/caldavd-test.plist 2008-04-26 00:24:43 UTC (rev 2351)
+++ CalendarServer/branches/users/wsanchez/logging/conf/caldavd-test.plist 2008-04-26 00:26:51 UTC (rev 2352)
@@ -250,6 +250,14 @@
<key>ErrorLogFile</key>
<string>logs/error.log</string>
+ <!-- Log Levels -->
+ <key>DefaultLogLevel</key>
+ <string>info</string> <!-- debug, info, warn, error -->
+
+ <key>LogLevels</key>
+ <dict>
+ </dict>
+
<!-- Server statistics file -->
<key>ServerStatsFile</key>
<string>logs/stats.plist</string>
Modified: CalendarServer/branches/users/wsanchez/logging/conf/caldavd.plist
===================================================================
--- CalendarServer/branches/users/wsanchez/logging/conf/caldavd.plist 2008-04-26 00:24:43 UTC (rev 2351)
+++ CalendarServer/branches/users/wsanchez/logging/conf/caldavd.plist 2008-04-26 00:26:51 UTC (rev 2352)
@@ -202,6 +202,10 @@
<key>ErrorLogFile</key>
<string>/var/log/caldavd/error.log</string>
+ <!-- Log Levels -->
+ <key>DefaultLogLevel</key>
+ <string>info</string> <!-- debug, info, warn, error -->
+
<!-- Server statistics file -->
<key>ServerStatsFile</key>
<string>/var/run/caldavd/stats.plist</string>
Modified: CalendarServer/branches/users/wsanchez/logging/twistedcaldav/config.py
===================================================================
--- CalendarServer/branches/users/wsanchez/logging/twistedcaldav/config.py 2008-04-26 00:24:43 UTC (rev 2351)
+++ CalendarServer/branches/users/wsanchez/logging/twistedcaldav/config.py 2008-04-26 00:26:51 UTC (rev 2352)
@@ -20,6 +20,7 @@
from twistedcaldav.py.plistlib import readPlist
from twistedcaldav.log import Logger
+from twistedcaldav.log import clearLogLevels, setLogLevelForNamespace, InvalidLogLevelError
log = Logger()
@@ -91,8 +92,8 @@
# Authentication
#
"Authentication": {
- "Basic" : { "Enabled": False }, # Clear text; best avoided
- "Digest" : { # Digest challenge/response
+ "Basic": { "Enabled": False }, # Clear text; best avoided
+ "Digest": { # Digest challenge/response
"Enabled": True,
"Algorithm": "md5",
"Qop": "",
@@ -107,11 +108,13 @@
# Logging
#
"Verbose": False,
- "AccessLogFile" : "/var/log/caldavd/access.log", # Apache-style access log
- "ErrorLogFile" : "/var/log/caldavd/error.log", # Server activity log
+ "AccessLogFile" : "/var/log/caldavd/access.log", # Apache-style access log
+ "ErrorLogFile" : "/var/log/caldavd/error.log", # Server activity log
"ServerStatsFile": "/var/run/caldavd/stats.plist",
"PIDFile" : "/var/run/caldavd.pid",
"RotateAccessLog": False,
+ "DefaultLogLevel": None,
+ "LogLevels": {},
#
# SSL/TLS
@@ -220,20 +223,32 @@
if param not in serviceDefaultParams[self._data["DirectoryService"]["type"]]:
del self._data["DirectoryService"]["params"][param]
- self.updateServerCapabilities()
-
- def updateServerCapabilities(self):
- """
- Change server capabilities based on the current config parameters.
- Here are the "features" in the config that need special treatment:
-
- EnableDropBox
- EnableNotifications
- """
+ #
+ # FIXME: Use the config object instead of doing this here
+ #
from twistedcaldav.resource import CalendarPrincipalResource
CalendarPrincipalResource.enableDropBox(self.EnableDropBox)
CalendarPrincipalResource.enableNotifications(self.EnableNotifications)
+ self.updateLogLevels()
+
+ def updateLogLevels(self):
+ clearLogLevels()
+
+ try:
+ if "DefaultLogLevel" in self._data:
+ level = self._data["DefaultLogLevel"]
+ if not level:
+ level = "info"
+ setLogLevelForNamespace(None, level)
+
+ if "LogLevels" in self._data:
+ for namespace in self._data["LogLevels"]:
+ setLogLevelForNamespace(namespace, self._data["LogLevels"][namespace])
+
+ except InvalidLogLevelError, e:
+ raise ConfigurationError("Invalid log level: %s" % (e.level))
+
def updateDefaults(self, items):
_mergeData(self._defaults, items)
self.update(items)
@@ -242,7 +257,7 @@
self._defaults = copy.deepcopy(defaults)
def __setattr__(self, attr, value):
- if '_data' in self.__dict__ and attr in self.__dict__['_data']:
+ if "_data" in self.__dict__ and attr in self.__dict__["_data"]:
self._data[attr] = value
else:
self.__dict__[attr] = value
Modified: CalendarServer/branches/users/wsanchez/logging/twistedcaldav/test/test_config.py
===================================================================
--- CalendarServer/branches/users/wsanchez/logging/twistedcaldav/test/test_config.py 2008-04-26 00:24:43 UTC (rev 2351)
+++ CalendarServer/branches/users/wsanchez/logging/twistedcaldav/test/test_config.py 2008-04-26 00:26:51 UTC (rev 2352)
@@ -17,7 +17,7 @@
from twisted.trial import unittest
from twistedcaldav.py.plistlib import writePlist
-
+from twistedcaldav.log import logLevelForNamespace
from twistedcaldav.config import config, defaultConfig, ConfigurationError
from twistedcaldav.static import CalDAVFile
@@ -25,10 +25,21 @@
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
+
<key>Verbose</key>
<true/>
+
<key>HTTPPort</key>
<integer>8008</integer>
+
+ <key>DefaultLogLevel</key>
+ <string>warn</string>
+ <key>LogLevels</key>
+ <dict>
+ <key>some.namespace</key>
+ <string>debug</string>
+ </dict>
+
</dict>
</plist>
"""
@@ -214,7 +225,6 @@
self.assertNotIn('Foo', defaultConfig)
def testComplianceClasses(self):
-
resource = CalDAVFile("/")
config.EnableProxyPrincipals = True
@@ -222,3 +232,21 @@
config.EnableProxyPrincipals = False
self.assertTrue("calendar-proxy" not in resource.davComplianceClasses())
+
+ def test_logging(self):
+ """
+ Logging module configures properly.
+ """
+ self.assertEquals(logLevelForNamespace(None), "info")
+ self.assertEquals(logLevelForNamespace("some.namespace"), "info")
+
+ config.loadConfig(self.testConfig)
+
+ self.assertEquals(logLevelForNamespace(None), "warn")
+ self.assertEquals(logLevelForNamespace("some.namespace"), "debug")
+
+ writePlist({}, self.testConfig)
+ config.reload()
+
+ self.assertEquals(logLevelForNamespace(None), "info")
+ self.assertEquals(logLevelForNamespace("some.namespace"), "info")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080425/1a4f1def/attachment-0001.html
More information about the calendarserver-changes
mailing list