Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ env*
.vagrant
flycheck-*
.idea
.vscode
.python-version
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ Contributors:
- Raphaël Vinot
- Rotem Yaari
- Frazer McLean

- Nguyễn Hồng Quân
7 changes: 4 additions & 3 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
Logbook Changelog
=================

Here you can see the full list of changes between each Logbook release.

Version 1.5.0
-------------

- Added support for asyncio
- Respect configuration of specific logger in compatibility mode

Version 1.4.3
-------------
Expand All @@ -22,8 +25,6 @@ Released on December 11th, 2018
- Try to reconnect to SyslogHandler TCP sockets when they are disconnected (thanks Jonathan Kamens)
- Use RFC 5424 format for networking logging in SyslogHandler (thanks Jonathan Kamens)

Here you can see the full list of changes between each Logbook release.

Version 1.4.1
-------------

Expand Down Expand Up @@ -72,7 +73,7 @@ Version 1.0.1
- Fix PushOver handler cropping (thanks Sébastien Celles)


VERSION 1.0.0
Version 1.0.0
-------------

Released on June 26th 2016
Expand Down
12 changes: 11 additions & 1 deletion logbook/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,22 @@ def __init__(self, logger=None, level=logbook.NOTSET, filter=None,
elif isinstance(logger, string_types):
logger = logging.getLogger(logger)
self.logger = logger
# Cache loggers of specific name
self.sublogs = {}

def get_logger(self, record):
"""Returns the logger to use for this record. This implementation
always return :attr:`logger`.
"""
return self.logger
name = record.channel
if name == self.logger.name or not name:
return self.logger
# Look up in cache
logger = self.sublogs.get(name)
if not logger:
logger = logging.getLogger(name)
self.sublogs[name] = logger
return logger

def convert_level(self, level):
"""Converts a logbook level into a logging level."""
Expand Down
53 changes: 53 additions & 0 deletions tests/test_logging_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,59 @@ def test_redirect_logbook():
logger.handlers[:] = old_handlers


def test_redirect_logbook_respect_specific_configuration():
import logging
import logging.config
out1 = StringIO()
out2 = StringIO()
config = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'brief': {
'format': '%(name)s:%(levelname)s:%(message)s'
}
},
'handlers': {
'console_1': {
'class': 'logging.StreamHandler',
'stream': out1,
'level': 'INFO',
},
'console_2': {
'class': 'logging.StreamHandler',
'stream': out2,
'level': 'INFO',
'formatter': 'brief'
},
},
'root': {
'level': 'INFO',
'handlers': ['console_1'],
},
'loggers': {
'module_2': {
'handlers': ['console_2'],
'propagate': False
}
},
}
logger = logging.getLogger()
logbook_logger = logbook.Logger('module_2')
old_handlers = logger.handlers[:]
logging.config.dictConfig(config)
try:
with logbook.compat.LoggingHandler():
logbook_logger.warn("This goes to logging")
pieces = out2.getvalue().strip().split(':')
# Check if our message goes to console_2
assert pieces == ['module_2', 'WARNING', 'This goes to logging']
# Check that our message doesn't go to console_1
assert out1.getvalue() == ''
finally:
logger.handlers[:] = old_handlers


from itertools import count
test_warning_redirections_i = count()

Expand Down