logging: add kwargs to fail() call
This commit is contained in:
parent
20b6b22334
commit
4ca33505b5
1 changed files with 6 additions and 6 deletions
|
@ -332,7 +332,7 @@ class LogUploader(object):
|
||||||
|
|
||||||
class Logger(logging.Logger):
|
class Logger(logging.Logger):
|
||||||
"""A logger that has an extra `fail` method useful for handling twisted failures."""
|
"""A logger that has an extra `fail` method useful for handling twisted failures."""
|
||||||
def fail(self, callback=None, *args):
|
def fail(self, callback=None, *args, **kwargs):
|
||||||
"""Returns a function to log a failure from an errback.
|
"""Returns a function to log a failure from an errback.
|
||||||
|
|
||||||
The returned function appends the error message and extracts
|
The returned function appends the error message and extracts
|
||||||
|
@ -355,20 +355,20 @@ class Logger(logging.Logger):
|
||||||
err: twisted.python.failure.Failure
|
err: twisted.python.failure.Failure
|
||||||
msg: the message to log, using normal logging string iterpolation.
|
msg: the message to log, using normal logging string iterpolation.
|
||||||
msg_args: the values to subtitute into `msg`
|
msg_args: the values to subtitute into `msg`
|
||||||
kwargs: set `level` to change from the default ERROR severity. Other
|
msg_kwargs: set `level` to change from the default ERROR severity. Other
|
||||||
keywoards are treated as normal log kwargs.
|
keywoards are treated as normal log kwargs.
|
||||||
"""
|
"""
|
||||||
fn, lno, func = findCaller()
|
fn, lno, func = findCaller()
|
||||||
def _fail(err, msg, *msg_args, **kwargs):
|
def _fail(err, msg, *msg_args, **msg_kwargs):
|
||||||
level = kwargs.pop('level', logging.ERROR)
|
level = msg_kwargs.pop('level', logging.ERROR)
|
||||||
msg += ": %s"
|
msg += ": %s"
|
||||||
msg_args += (err.getErrorMessage(),)
|
msg_args += (err.getErrorMessage(),)
|
||||||
exc_info = (err.type, err.value, err.getTracebackObject())
|
exc_info = (err.type, err.value, err.getTracebackObject())
|
||||||
record = self.makeRecord(
|
record = self.makeRecord(
|
||||||
self.name, level, fn, lno, msg, msg_args, exc_info, func, kwargs)
|
self.name, level, fn, lno, msg, msg_args, exc_info, func, msg_kwargs)
|
||||||
self.handle(record)
|
self.handle(record)
|
||||||
if callback:
|
if callback:
|
||||||
callback(err, *args)
|
callback(err, *args, **kwargs)
|
||||||
return _fail
|
return _fail
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue