From 0a59991ce6ec03358bc1d002658b5540b75e915c Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@lothar.com>
Date: Sat, 20 Sep 2008 10:35:45 -0700
Subject: [PATCH] various: use util.log.err instead of twisted.log.err, so we
 get both Incidents and trial-test-flunking

---
 src/allmydata/key_generator.py   |  2 +-
 src/allmydata/mutable/node.py    |  3 +--
 src/allmydata/node.py            | 14 +++++++-------
 src/allmydata/offloaded.py       |  6 +++---
 src/allmydata/util/assertutil.py |  2 +-
 5 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/src/allmydata/key_generator.py b/src/allmydata/key_generator.py
index 97f7b13e..57a3fd1c 100644
--- a/src/allmydata/key_generator.py
+++ b/src/allmydata/key_generator.py
@@ -6,7 +6,7 @@ import foolscap
 from zope.interface import implements
 from twisted.internet import reactor
 from twisted.application import service
-from twisted.python import log
+from allmydata.util import log
 
 from pycryptopp.publickey import rsa
 from allmydata.interfaces import RIKeyGenerator
diff --git a/src/allmydata/mutable/node.py b/src/allmydata/mutable/node.py
index b70e0c15..d8991fca 100644
--- a/src/allmydata/mutable/node.py
+++ b/src/allmydata/mutable/node.py
@@ -4,11 +4,10 @@ from twisted.application import service
 
 from zope.interface import implements
 from twisted.internet import defer, reactor
-from twisted.python import log
 from foolscap.eventual import eventually
 from allmydata.interfaces import IMutableFileNode, IMutableFileURI, \
      ICheckable, ICheckerResults
-from allmydata.util import hashutil
+from allmydata.util import hashutil, log
 from allmydata.util.assertutil import precondition
 from allmydata.uri import WriteableSSKFileURI
 from allmydata.immutable.encode import NotEnoughSharesError
diff --git a/src/allmydata/node.py b/src/allmydata/node.py
index 0757d587..8ad62706 100644
--- a/src/allmydata/node.py
+++ b/src/allmydata/node.py
@@ -2,7 +2,7 @@
 import datetime, os.path, re, types
 from base64 import b32decode, b32encode
 
-from twisted.python import log as tahoe_log
+from twisted.python import log as twlog
 from twisted.application import service
 from twisted.internet import defer, reactor
 from foolscap import Tub, eventual
@@ -175,12 +175,12 @@ class Node(service.MultiService):
 
     def _service_startup_failed(self, failure):
         self.log('_startService() failed')
-        tahoe_log.err(failure)
+        log.err(failure)
         print "Node._startService failed, aborting"
         print failure
         #reactor.stop() # for unknown reasons, reactor.stop() isn't working.  [ ] TODO
         self.log('calling os.abort()')
-        tahoe_log.msg('calling os.abort()')
+        twlog.msg('calling os.abort()') # make sure it gets into twistd.log
         print "calling os.abort()"
         os.abort()
 
@@ -202,11 +202,11 @@ class Node(service.MultiService):
     def setup_logging(self):
         # we replace the formatTime() method of the log observer that twistd
         # set up for us, with a method that uses better timestamps.
-        for o in tahoe_log.theLogPublisher.observers:
+        for o in twlog.theLogPublisher.observers:
             # o might be a FileLogObserver's .emit method
             if type(o) is type(self.setup_logging): # bound method
                 ob = o.im_self
-                if isinstance(ob, tahoe_log.FileLogObserver):
+                if isinstance(ob, twlog.FileLogObserver):
                     newmeth = types.UnboundMethodType(formatTimeTahoeStyle, ob, ob.__class__)
                     ob.formatTime = newmeth
         # TODO: twisted >2.5.0 offers maxRotatedFiles=50
@@ -234,8 +234,8 @@ class Node(service.MultiService):
             except TypeError, e:
                 msg = "ERROR: output string '%s' contained invalid %% expansion, error: %s, args: %s\n" % (`msg`, e, `args`)
         msg = self.short_nodeid + ": " + humanreadable.hr(msg)
-        return tahoe_log.callWithContext({"system":logsrc},
-                                         tahoe_log.msg, msg, **kw)
+        return twlog.callWithContext({"system":logsrc},
+                                     twlog.msg, msg, **kw)
 
     def _setup_tub(self, local_addresses):
         # we can't get a dynamically-assigned portnum until our Tub is
diff --git a/src/allmydata/offloaded.py b/src/allmydata/offloaded.py
index 8ed82e26..f2a8afad 100644
--- a/src/allmydata/offloaded.py
+++ b/src/allmydata/offloaded.py
@@ -3,7 +3,7 @@ import os, stat, time, weakref
 from zope.interface import implements
 from twisted.application import service
 from twisted.internet import defer
-from foolscap import Referenceable
+from foolscap import Referenceable, DeadReferenceError
 from foolscap.eventual import eventually
 from allmydata import interfaces, storage, uri
 from allmydata.immutable import upload
@@ -73,8 +73,8 @@ class CHKCheckerAndUEBFetcher:
                                 for bucket in buckets.values() ] )
 
     def _got_error(self, f):
-        if f.check(KeyError):
-            pass
+        if f.check(DeadReferenceError):
+            return
         log.err(f, parent=self._logparent)
         pass
 
diff --git a/src/allmydata/util/assertutil.py b/src/allmydata/util/assertutil.py
index 32cd12ca..005ab16c 100644
--- a/src/allmydata/util/assertutil.py
+++ b/src/allmydata/util/assertutil.py
@@ -11,7 +11,7 @@ Tests useful in assertion checking, prints out nicely formated messages too.
 
 from humanreadable import hr
 
-from twisted.python import log
+from allmydata.util import log
 
 def _assert(___cond=False, *___args, **___kwargs):
     if ___cond:
-- 
2.45.2