Commit e3804008 authored by Jérome Perrin's avatar Jérome Perrin

ERP5Type: fix logger "name" when logging warnings

Instead of using an always-different logger name which confuses log
analytics system, use the warning category as logger name (or what zLOG.LOG
calls "subsystem")
parent 21c271cd
......@@ -220,8 +220,7 @@ warnings.simplefilter("default")
def _showwarning(message, category, filename, lineno, file=None, line=None):
if file is None:
LOG("%s:%u %s: %s" % (filename, lineno, category.__name__, message),
WARNING, '')
LOG(category.__name__, WARNING, "%s:%u %s" % (filename, lineno, message))
else:
file.write(warnings.formatwarning(message, category, filename, lineno, line))
warnings.showwarning = _showwarning
......
......@@ -32,6 +32,7 @@ of Portal Type as Classes and ZODB Components
"""
import unittest
import warnings
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.ZopeGuards import guarded_import
from Products.ERP5Type.tests.utils import LogInterceptor
......@@ -243,6 +244,17 @@ class TestERP5Type(ERP5TypeTestCase, LogInterceptor):
self.assertTrue(o.isTempObject())
self.assertTrue(guarded_import("Products.ERP5Type.Document", fromlist=["newTempBase"]))
def test_warnings_redirected_to_event_log(self):
self._catch_log_errors()
self.addCleanup(self._ignore_log_errors)
warnings.warn('user warning')
self.assertEqual(self.logged[-1].name, 'UserWarning')
self.assertIn('Products/ERP5Type/tests/testERP5Type.py', self.logged[-1].message)
self.assertIn('user warning', self.logged[-1].message)
warnings.warn('user warning', DeprecationWarning)
self.assertEqual(self.logged[-1].name, 'DeprecationWarning')
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestERP5Type))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment