subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gst...@apache.org
Subject svn commit: r1296006 - /subversion/trunk/tools/server-side/svnpubsub/svnwcsub.tac
Date Fri, 02 Mar 2012 00:11:56 GMT
Author: gstein
Date: Fri Mar  2 00:11:55 2012
New Revision: 1296006

URL: http://svn.apache.org/viewvc?rev=1296006&view=rev
Log:
Use a crazy hack to inject Twisted's log output into the Python
logging framework.

Temporary: we're in-process on moving away from Twisted.

* tools/server-side/svnpubsub/svnwcsub.tac:
  (capture_log): crazy hack to watch for log output from Twisted, then
    track down the logfile.LogFile object. then pass its output stream
    over to the Python framework (and remove itself at that point).

Modified:
    subversion/trunk/tools/server-side/svnpubsub/svnwcsub.tac

Modified: subversion/trunk/tools/server-side/svnpubsub/svnwcsub.tac
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/server-side/svnpubsub/svnwcsub.tac?rev=1296006&r1=1296005&r2=1296006&view=diff
==============================================================================
--- subversion/trunk/tools/server-side/svnpubsub/svnwcsub.tac (original)
+++ subversion/trunk/tools/server-side/svnpubsub/svnwcsub.tac Fri Mar  2 00:11:55 2012
@@ -22,15 +22,48 @@ from twisted.application import service,
 
 sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
 
-from svnwcsub import ReloadableConfig, BigDoEverythingClasss
+import svnwcsub
 
 application = service.Application("SvnWcSub")
 
 def get_service():
     m = service.MultiService()
-    c = ReloadableConfig("/etc/svnwcsub.conf")
-    big = BigDoEverythingClasss(c, service=m)
+    c = svnwcsub.ReloadableConfig("/etc/svnwcsub.conf")
+    big = svnwcsub.BigDoEverythingClasss(c, service=m)
     return m
 
 service = get_service()
 service.setServiceParent(application)
+
+
+### crazy hack. the first time Twisted logs something, we will track down
+### the logfile it is using, then use that for the Python logging framework
+from twisted.python import log
+import logging
+
+def capture_log(unused_msg):
+    for ob in log.theLogPublisher.observers:
+        if hasattr(ob, 'im_class') and ob.im_class is log.FileLogObserver:
+            flo = ob.im_self
+            logfile = flo.write.im_self
+            stream = logfile._file
+
+            ### the follow is similar to svnwcsub.prepare_logging()
+            handler = logging.StreamHandler(stream)
+            formatter = logging.Formatter(
+                            '%(asctime)s [%(levelname)s] %(message)s',
+                            '%Y-%m-%d %H:%M:%S')
+            handler.setFormatter(formatter)
+
+            # Apply the handler to the root logger
+            root = logging.getLogger()
+            root.addHandler(handler)
+
+            ### use logging.INFO for now
+            root.setLevel(logging.INFO)
+
+            # okay. remove our capture function.
+            log.removeObserver(capture_log)
+
+# hook in the capturing...
+log.addObserver(capture_log)



Mime
View raw message