[CalendarServer-changes] [11348] CalendarServer/trunk/twext/python/log.py
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jun 13 16:20:35 PDT 2013
Revision: 11348
http://trac.calendarserver.org//changeset/11348
Author: wsanchez at apple.com
Date: 2013-06-13 16:20:35 -0700 (Thu, 13 Jun 2013)
Log Message:
-----------
cosmetic
Modified Paths:
--------------
CalendarServer/trunk/twext/python/log.py
Modified: CalendarServer/trunk/twext/python/log.py
===================================================================
--- CalendarServer/trunk/twext/python/log.py 2013-06-13 23:19:17 UTC (rev 11347)
+++ CalendarServer/trunk/twext/python/log.py 2013-06-13 23:20:35 UTC (rev 11348)
@@ -75,13 +75,11 @@
]
from sys import stdout, stderr
-
+from string import Formatter
import inspect
import logging
import time
-from string import Formatter
-
from zope.interface import Interface, implementer
from twisted.python.constants import NamedConstant, Names
from twisted.python.failure import Failure
@@ -142,56 +140,7 @@
#LogLevel.critical: logging.CRITICAL,
}
-_theFormatter = Formatter()
-
-
-class _CallMapping(object):
- def __init__(self, submapping):
- self._submapping = submapping
-
- def __getitem__(self, key):
- callit = key.endswith(u"()")
- realKey = key[:-2] if callit else key
- value = self._submapping[realKey]
- if callit:
- value = value()
- return value
-
-
-
-def formatWithCall(formatString, mapping):
- """
- Format a string like L{unicode.format}, but:
-
- - taking only a name mapping; no positional arguments
-
- - with the additional syntax that an empty set of parentheses
- correspond to a formatting item that should be called, and its result
- C{str}'d, rather than calling C{str} on the element directly as
- normal.
-
- For example::
-
- >>> formatWithCall("{string}, {function()}.",
- ... dict(string="just a string",
- ... function=lambda: "a function"))
- 'just a string, a function.'
-
- @param formatString: A PEP-3101 format string.
- @type formatString: L{unicode}
-
- @param mapping: A L{dict}-like object to format.
-
- @return: The string with formatted values interpolated.
- @rtype: L{unicode}
- """
- return unicode(
- _theFormatter.vformat(formatString, (), _CallMapping(mapping))
- )
-
-
-
#
# Tools for managing log levels
#
@@ -695,7 +644,6 @@
def __str__(self):
return self.formatEvent(event)
- # FIXME: Adding the prefix should be the observer's problem
event["format"] = prefix + "%(log_legacy)s"
event["log_legacy"] = LegacyFormatStub()
@@ -711,12 +659,67 @@
+#
+# Utilities
+#
+class CallMapping(object):
+ def __init__(self, submapping):
+ self._submapping = submapping
+
+ def __getitem__(self, key):
+ callit = key.endswith(u"()")
+ realKey = key[:-2] if callit else key
+ value = self._submapping[realKey]
+ if callit:
+ value = value()
+ return value
+
+
+def formatWithCall(formatString, mapping):
+ """
+ Format a string like L{unicode.format}, but:
+
+ - taking only a name mapping; no positional arguments
+
+ - with the additional syntax that an empty set of parentheses
+ correspond to a formatting item that should be called, and its result
+ C{str}'d, rather than calling C{str} on the element directly as
+ normal.
+
+ For example::
+
+ >>> formatWithCall("{string}, {function()}.",
+ ... dict(string="just a string",
+ ... function=lambda: "a function"))
+ 'just a string, a function.'
+
+ @param formatString: A PEP-3101 format string.
+ @type formatString: L{unicode}
+
+ @param mapping: A L{dict}-like object to format.
+
+ @return: The string with formatted values interpolated.
+ @rtype: L{unicode}
+ """
+ return unicode(
+ _theFormatter.vformat(formatString, (), CallMapping(mapping))
+ )
+
+_theFormatter = Formatter()
+
+
+
+#
+# Default observers
+# FIXME: ...
+#
TheLegacyLogObserver = LegacyLogObserverWrapper(twistedLogMessage)
TheFilteredLogPublisher = LogPublisher(TheLegacyLogObserver) # Add post-filtering observers here
TheFilteringLogObserver = LogLevelFilteringLogObserverWrapper(TheFilteredLogPublisher)
TheLogPublisher = LogPublisher(TheFilteringLogObserver) # Add pre-filtering observers here
+
######################################################################
# FIXME: This may not be needed; look into removing it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130613/b074a9b8/attachment-0001.html>
More information about the calendarserver-changes
mailing list