Skip to content

Commit

Permalink
#19 Pass positional arguments down to stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
gcbirzan committed Dec 16, 2013
1 parent 59ed7af commit dde8347
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Changelog
=========

- :bug:`19` Pass positional arguments to stdlib wrapped loggers that use string formatting.
- :bug:`-` Various doc fixes.
- :release:`0.4.0 <2013-11-10>`
- :feature:`6` Add :class:`structlog.processors.StackInfoRenderer` for adding stack information to log entries without involving exceptions.
Expand Down
3 changes: 2 additions & 1 deletion structlog/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _process_event(self, method_name, event, event_kw):
else:
return event_dict

def _proxy_to_logger(self, method_name, event=None, **event_kw):
def _proxy_to_logger(self, method_name, event=None, *event_args, **event_kw):
"""
Run processor chain on event & call *method_name* on wrapped logger.
Expand All @@ -168,6 +168,7 @@ def _proxy_to_logger(self, method_name, event=None, **event_kw):
"""
try:
args, kw = self._process_event(method_name, event, event_kw)
args = args[:] + event_args
return getattr(self._logger, method_name)(*args, **kw)
except DropEvent:
return
20 changes: 10 additions & 10 deletions structlog/stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,37 @@ class BoundLogger(BoundLoggerBase):
)
"""
def debug(self, event=None, **kw):
def debug(self, event=None, *args, **kw):
"""
Process event and call ``Logger.debug()`` with the result.
"""
return self._proxy_to_logger('debug', event, **kw)
return self._proxy_to_logger('debug', event, *args, **kw)

def info(self, event=None, **kw):
def info(self, event=None, *args, **kw):
"""
Process event and call ``Logger.info()`` with the result.
"""
return self._proxy_to_logger('info', event, **kw)
return self._proxy_to_logger('info', event, *args, **kw)

def warning(self, event=None, **kw):
def warning(self, event=None, *args, **kw):
"""
Process event and call ``Logger.warning()`` with the result.
"""
return self._proxy_to_logger('warning', event, **kw)
return self._proxy_to_logger('warning', event, *args, **kw)

warn = warning

def error(self, event=None, **kw):
def error(self, event=None, *args, **kw):
"""
Process event and call ``Logger.error()`` with the result.
"""
return self._proxy_to_logger('error', event, **kw)
return self._proxy_to_logger('error', event, *args, **kw)

def critical(self, event=None, **kw):
def critical(self, event=None, *args, **kw):
"""
Process event and call ``Logger.critical()`` with the result.
"""
return self._proxy_to_logger('critical', event, **kw)
return self._proxy_to_logger('critical', event, *args, **kw)


class LoggerFactory(object):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,11 @@ def return_method_name(_, method_name, __):
return method_name
bl = BoundLogger(ReturnLogger(), [return_method_name], {})
assert method_name == getattr(bl, method_name)('event')

@pytest.mark.parametrize(('method_name'), [
'debug', 'info', 'warning', 'error', 'critical',
])
def test_positional_arguments(self, method_name):
bl = BoundLogger(ReturnLogger(), [lambda *x: repr(x[2])], {})
res = getattr(bl, method_name)("%d %d %s", 1, 2, "test")
assert res[0] == ("{'event': '%d %d %s'}", 1, 2, 'test')

0 comments on commit dde8347

Please sign in to comment.