mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-20 09:46:18 +00:00
Clean up log.err calls, for one of the issues in #889.
allmydata.util.log.err() either takes a Failure as the first positional argument, or takes no positional arguments and must be invoked in an exception handler. Fixed its signature to match both foolscap.logging.log.err and twisted.python.log.err . Included a brief unit test.
This commit is contained in:
parent
bacb6fe5aa
commit
d888bf3377
@ -118,10 +118,10 @@ class Checker(log.PrefixingLogMixin):
|
||||
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")
|
||||
|
||||
|
||||
|
@ -770,10 +770,10 @@ class ServermapUpdater:
|
||||
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):
|
||||
|
@ -162,7 +162,7 @@ class FakeBucketWriter:
|
||||
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,
|
||||
|
@ -12,6 +12,7 @@ from allmydata.util import base32, idlib, humanreadable, mathutil, hashutil
|
||||
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):
|
||||
@ -1492,3 +1493,21 @@ class Pipeline(unittest.TestCase):
|
||||
|
||||
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)
|
||||
|
@ -20,11 +20,11 @@ msg = log.msg
|
||||
# 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() """
|
||||
|
Loading…
x
Reference in New Issue
Block a user