Skip to content
Browse files

Add DefaultLogPublisher

  • Loading branch information...
wsanchez committed Jun 17, 2013
1 parent ddcb435 commit 02c1c03a93a6ed1cfa33b8762530e1c3c83aa746
Showing with 60 additions and 6 deletions.
  1. +60 −6 twext/python/
@@ -717,6 +717,64 @@ def __str__(oself):

# FIXME: This could have a better name.
class DefaultLogPublisher(object):
The default log publisher. This observer sets up a set of chained observers
as follows:
1. B{rootPublisher} - a L{LogPublisher}
2. B{filteringObserver}: a L{FilteringLogObserver} that filters out
messages using a L{LogLevelFilterPredicate}
3. B{filteredPublisher} - a L{LogPublisher}
4. B{legacyLogObserver} - a A{LegacyLogObserver} wired up to
The purpose of this class is to provide a default log observer with
sufficient hooks to enable applications to add observers that can either
receive all log messages, or only log messages that are configured to pass
though the L{LogLevelFilterPredicate}::
from twext.python.log import Logger, ILogObserver
log = Logger()
class AMPObserver(object):
def __call__(self, event):
# eg.: Hold all emitted events in a ring buffer and expose them
# via AMP.
class FileObserver(object):
def __call__(self, event):
# eg.: Take only the filtered events and write them into a
# file.
With no observers added, the default behavior is that the legacy Twisted
logging system sees messages as controlled by L{LogLevelFilterPredicate}.

def __init__(self):
self.legacyLogObserver = LegacyLogObserver(twistedLogMessage)
self.filteredPublisher = LogPublisher(self.legacyLogObserver)
self.filteringObserver = FilteringLogObserver(self.filteredPublisher, (LogLevelFilterPredicate(),))
self.rootPublisher = LogPublisher(self.filteringObserver)

def __call__(self, event):

# Utilities
@@ -769,13 +827,9 @@ def formatWithCall(formatString, mapping):

# Default observers
# FIXME: ...
# Wire up default publisher
theLegacyLogObserver = LegacyLogObserver(twistedLogMessage)
theFilteredLogPublisher = LogPublisher(theLegacyLogObserver) # Add post-filtering observers here
theFilteringLogObserver = FilteringLogObserver(theFilteredLogPublisher, (LogLevelFilterPredicate(),))
Logger.publisher = LogPublisher(theFilteringLogObserver) # Add pre-filtering observers here
Logger.publisher = DefaultLogPublisher()

0 comments on commit 02c1c03

Please sign in to comment.
You can’t perform that action at this time.