[CalendarServer-changes] [4410] CalendarServer/trunk/twext/python/log.py
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jul 2 11:35:48 PDT 2009
Revision: 4410
http://trac.macosforge.org/projects/calendarserver/changeset/4410
Author: wsanchez at apple.com
Date: 2009-07-02 11:35:47 -0700 (Thu, 02 Jul 2009)
Log Message:
-----------
Add StandardIOObserver
Added Paths:
-----------
CalendarServer/trunk/twext/python/log.py
Added: CalendarServer/trunk/twext/python/log.py
===================================================================
--- CalendarServer/trunk/twext/python/log.py (rev 0)
+++ CalendarServer/trunk/twext/python/log.py 2009-07-02 18:35:47 UTC (rev 4410)
@@ -0,0 +1,49 @@
+##
+# Copyright (c) 2009 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+"""
+Extensions to twisted.python.log.
+"""
+
+from sys import stdout, stderr
+
+from twisted.python.log import addObserver
+
+class StandardIOObserver (object):
+ """
+ Log observer that writes to standard I/O.
+ """
+ def emit(self, eventDict):
+ text = None
+
+ if eventDict["isError"]:
+ output = stderr
+ if "failure" in eventDict:
+ text = eventDict["failure"].getTraceback()
+ else:
+ output = stdout
+
+ if not text:
+ text = " ".join([str(m) for m in eventDict["message"]]) + "\n"
+
+ output.write(text)
+ output.flush()
+
+ def start(self):
+ addObserver(self.emit)
+
+ def stop(self):
+ removeObserver(self.emit)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090702/c470fc5b/attachment.html>
More information about the calendarserver-changes
mailing list