level=log.WEIRD, umid="atbAxw")
return
# local errors are cause for alarm
- log.err(format="local error in add_lease to [%(peerid)s]: %(f_value)s",
+ log.err(f,
+ format="local error in add_lease to [%(peerid)s]: %(f_value)s",
peerid=idlib.shortnodeid_b2a(peerid),
f_value=str(f.value),
- failure=f,
level=log.WEIRD, umid="hEGuQg")
level=log.WEIRD, umid="iqg3mw")
return
# local errors are cause for alarm
- log.err(format="local error in add_lease to [%(peerid)s]: %(f_value)s",
+ log.err(f,
+ format="local error in add_lease to [%(peerid)s]: %(f_value)s",
peerid=idlib.shortnodeid_b2a(peerid),
f_value=str(f.value),
- failure=f,
level=log.WEIRD, umid="ZWh6HA")
def _query_failed(self, f, peerid):
self.closed = True
def remote_abort(self):
- log.err("uh oh, I was asked to abort")
+ log.err(RuntimeError("uh oh, I was asked to abort"))
class FakeClient:
DEFAULT_ENCODING_PARAMETERS = {"k":25,
from allmydata.util import assertutil, fileutil, deferredutil, abbreviate
from allmydata.util import limiter, time_format, pollmixin, cachedir
from allmydata.util import statistics, dictutil, pipeline
+from allmydata.util import log as tahoe_log
class Base32(unittest.TestCase):
def test_b2a_matches_Pythons(self):
self.calls[1][0].callback("two-result")
self.calls[2][0].errback(ValueError("three-error"))
+
+class SampleError(Exception):
+ pass
+
+class Log(unittest.TestCase):
+ def test_err(self):
+ if not hasattr(self, "flushLoggedErrors"):
+ # without flushLoggedErrors, we can't get rid of the
+ # twisted.log.err that tahoe_log records, so we can't keep this
+ # test from [ERROR]ing
+ raise unittest.SkipTest("needs flushLoggedErrors from Twisted-2.5.0")
+ try:
+ raise SampleError("simple sample")
+ except:
+ f = Failure()
+ tahoe_log.err(format="intentional sample error",
+ failure=f, level=tahoe_log.OPERATIONAL, umid="wO9UoQ")
+ self.flushLoggedErrors(SampleError)
# thing happens that is nevertheless handled, use log.msg(failure=f,
# level=WEIRD) instead.
-def err(*args, **kwargs):
- tw_log.err(*args, **kwargs)
+def err(failure=None, _why=None, **kwargs):
+ tw_log.err(failure, _why, **kwargs)
if 'level' not in kwargs:
kwargs['level'] = log.UNUSUAL
- return log.err(*args, **kwargs)
+ return log.err(failure, _why, **kwargs)
class LogMixin(object):
""" I remember a msg id and a facility and pass them to log.msg() """