Skip to content

Commit

Permalink
bpo-31457: Make the LoggerAdapter.manager property settable (python…
Browse files Browse the repository at this point in the history
…#4042)

Due to a bug in the initial fix, the setter was in fact creating a different
property.  This is now fixed.
  • Loading branch information
ambv authored Oct 19, 2017
1 parent 032a648 commit 0b6a118
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Lib/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ def manager(self):
return self.logger.manager

@manager.setter
def set_manager(self, value):
def manager(self, value):
self.logger.manager = value

def __repr__(self):
Expand Down
15 changes: 14 additions & 1 deletion Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3982,12 +3982,25 @@ def test_nested(self):
msg = 'Adapters can be nested, yo.'
adapter_adapter = logging.LoggerAdapter(logger=self.adapter, extra=None)
adapter_adapter.log(logging.CRITICAL, msg, self.recording)

self.assertEqual(len(self.recording.records), 1)
record = self.recording.records[0]
self.assertEqual(record.levelno, logging.CRITICAL)
self.assertEqual(record.msg, msg)
self.assertEqual(record.args, (self.recording,))
orig_manager = adapter_adapter.manager
self.assertIs(self.adapter.manager, orig_manager)
self.assertIs(self.logger.manager, orig_manager)
temp_manager = object()
try:
adapter_adapter.manager = temp_manager
self.assertIs(adapter_adapter.manager, temp_manager)
self.assertIs(self.adapter.manager, temp_manager)
self.assertIs(self.logger.manager, temp_manager)
finally:
adapter_adapter.manager = orig_manager
self.assertIs(adapter_adapter.manager, orig_manager)
self.assertIs(self.adapter.manager, orig_manager)
self.assertIs(self.logger.manager, orig_manager)


class LoggerTest(BaseTest):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The ``manager`` property on LoggerAdapter objects is now properly settable.

0 comments on commit 0b6a118

Please sign in to comment.