#11874 closed enhancement (fixed)
Allowing logger to be extended with different handlers
Reported by: | Ryan J Ollos | Owned by: | Ryan J Ollos |
---|---|---|---|
Priority: | normal | Milestone: | 1.3.1 |
Component: | general | Version: | |
Severity: | normal | Keywords: | logging |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: |
|
||
Internal Changes: |
Description (last modified by )
Adding a LoggerManager
Component and a ILoggingHandlerProvider
interface would allow new handlers to be added through plugins. It should also be possible to eliminate some redundant definitions of log types in log.py
and admin/web_ui.py
, and provide a cleaner definition of log levels.
One handler that will be of immediate use is the addition of MockLoggingHandler
in test.py
, taken from SO:1049375/121694.
Attachments (0)
Change History (17)
comment:1 by , 10 years ago
Description: | modified (diff) |
---|---|
Keywords: | logging added; log removed |
Type: | defect → enhancement |
comment:2 by , 10 years ago
Description: | modified (diff) |
---|
comment:3 by , 10 years ago
Description: | modified (diff) |
---|
comment:4 by , 10 years ago
Milestone: | 1.1.4 → 1.1.5 |
---|
comment:5 by , 10 years ago
Milestone: | 1.1.5 → 1.2 |
---|
comment:7 by , 10 years ago
Milestone: | 1.1.6 → next-dev-1.1.x |
---|
comment:8 by , 10 years ago
Owner: | removed |
---|
comment:9 by , 9 years ago
Milestone: | next-dev-1.1.x → next-dev-1.3.x |
---|
Narrowing focus for milestone:1.2. Please move ticket to milestone:1.2 if you intend to fix it.
comment:10 by , 9 years ago
The changes in this ticket can also include the addition of LogRecordFilter
proposed in #7820. The change was not included in that ticket because it would have resulted in an API change.
class LogRecordFilter(logging.Filter): def __init__(self, path, basename, project): super(LogRecordFilter, self).__init__() self.path = path self.basename = basename self.project = project def filter(self, record): record.path = self.path record.basename = self.basename record.project = self.project return True
comment:11 by , 8 years ago
Milestone: | next-dev-1.3.x → 1.3.1 |
---|---|
Owner: | set to |
Status: | new → assigned |
Since #7820 allows the logger to be configured from a file, rather than adding an extension point I think we can just use StreamHandler in EnvironmentStub
, and have EnvironmentStub
utilize StreamHandler
to log to a stream buffer target
that we can make assertions again.
follow-up: 13 comment:12 by , 8 years ago
Proposed changes in log:rjollos.git:t11874_mock_logger.
I'd like to avoid use of StringIO.StringIO
after #12046, however I'm having some trouble with that.
Use of io.StringIO
results in:
Traceback (most recent call last): File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 882, in emit stream.write(fs % msg) TypeError: unicode argument expected, got 'str' Logged from file main.py, line 191
Use of io.BytesIO
results in:
Traceback (most recent call last): File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 882, in emit stream.write(fs % msg) TypeError: 'unicode' does not have the buffer interface Logged from file main.py, line 176
comment:13 by , 8 years ago
Replying to Ryan J Ollos:
Proposed changes in log:rjollos.git:t11874_mock_logger.
I'd like to avoid use of
StringIO.StringIO
after #12046, however I'm having some trouble with that.
Changed to use BufferingHandler
in [81740a12/rjollos.git].
comment:14 by , 8 years ago
[ab85dc14/rjollos.git] changes EnvironmentStub.log_messages
to return a list of tuples with (level_name, message)
.
comment:15 by , 8 years ago
Looks good to me. However I'm not sure about adding self.assertEqual('DEBUG', level)
in [ab85dc14/rjollos.git].
It seems that test case confirms Can't authenticate using ...
in log messages from rjollos.git/trac/web/main.py@ab85dc14:174-176#L169. I think the test case should be this:
-
trac/web/tests/main.py
diff --git a/trac/web/tests/main.py b/trac/web/tests/main.py index f9fcb6db2..0cefc6711 100644
a b class AuthenticateTestCase(unittest.TestCase): 120 120 self.request_dispatcher.authenticate(self.req)) 121 121 self.assertEqual(1, len(self.req.chrome['warnings'])) 122 122 expected = "Can't authenticate using RaisingAuthenticator: " 123 level = None124 123 for level, message in self.env.log_messages: 125 124 if expected in message.split('\n'): 125 self.assertEqual('ERROR', level) 126 126 break 127 127 else: 128 self.assertEqual('DEBUG', level)129 128 self.fail("Expected log message not found: \"%s\"" % expected) 130 129 131 130 def test_authenticate_once(self):
comment:16 by , 8 years ago
API Changes: | modified (diff) |
---|---|
Release Notes: | modified (diff) |
Resolution: | → fixed |
Status: | assigned → closed |
Thanks for spotting that error. Changes committed to trunk in r15129, including patch from comment:15. Additional changes in r15130. I'll continue with related work on logging system in #7820.
The Travis CI build failures on OSX were resolved by clearing the caches.
Narrowing focus for 1.1.4.