Commit 0acd98ac authored by Guido van Rossum's avatar Guido van Rossum

Several changes to the zLOG/logging/ZConfig connection:

(1) Change the mapping from zLOG levels to logging levels to use
    custom intermediary levels 15 and 5 for BLATHER and TRACE, rather
    than using a confusing skewed mapping.

(2) In the ZConfig datatype definition for a logging level, added
    'blather' and 'trace' to the level names, added 'warning' as an
    alias for 'warn', change 'all' to mean 1, and add 'notset' to mean
    0.  The semantics of NOTSET are very different than those of 1;
    setting a logger's level to NOTSET searches for a parent logger
    with a nonzero level.  The root of all loggers is initialized with
    WARN as its level, so setting the level to NOTSET effectively sets
    it to WARN rather than to the most inclusive level!

(3) In the schema, change the default level for handlers to notset, so
    they use their logger's level; the default level for the logger is
    set to info, corresponding to the old default for
    STUPID_LOG_SEVERITY.
parent 64d1d28b
...@@ -25,6 +25,12 @@ from BaseLogger import BaseLogger ...@@ -25,6 +25,12 @@ from BaseLogger import BaseLogger
from LogHandlers import FileHandler, NullHandler, SysLogHandler from LogHandlers import FileHandler, NullHandler, SysLogHandler
from logging import StreamHandler, Formatter from logging import StreamHandler, Formatter
# Custom logging levels
CUSTOM_BLATHER = 15 # Mapping for zLOG.BLATHER
CUSTOM_TRACE = 5 # Mapping for zLOG.TRACE
logging.addLevelName("BLATHER", CUSTOM_BLATHER)
logging.addLevelName("TRACE", CUSTOM_TRACE)
class EventLogger(BaseLogger): class EventLogger(BaseLogger):
# Get our logger object: # Get our logger object:
...@@ -82,23 +88,30 @@ def zlog_to_pep282_severity(zlog_severity): ...@@ -82,23 +88,30 @@ def zlog_to_pep282_severity(zlog_severity):
zLOG severity PEP282 severity zLOG severity PEP282 severity
------------- --------------- ------------- ---------------
PANIC (300) critical (50) PANIC (300) FATAL, CRITICAL (50)
ERROR (200), PROBLEM (100) error (40) ERROR (200) ERROR (40)
INFO (0) warn (30) WARNING, PROBLEM (100) WARN (30)
BLATHER (-100) info (20) INFO (0) INFO (20)
DEBUG (-200), TRACE (-300) debug (10) BLATHER (-100) BLATHER (15) [*]
DEBUG (-200) DEBUG (10)
TRACE (-300) TRACE (5) [*]
[*] BLATHER and TRACE are custom logging levels.
""" """
sev = zlog_severity sev = zlog_severity
if sev >= 300: if sev >= 300:
return logging.CRITICAL return logging.FATAL
if sev >= 100: if sev >= 200:
return logging.ERROR return logging.ERROR
if sev >= 0: if sev >= 100:
return logging.WARN return logging.WARN
if sev >= -100: if sev >= 0:
return logging.INFO return logging.INFO
else: if sev >= -100:
return CUSTOM_BLATHER
if sev >= -200:
return logging.DEBUG return logging.DEBUG
return CUSTOM_TRACE
zlog_to_pep282_severity_cache = {} zlog_to_pep282_severity_cache = {}
for _sev in range(-300, 301, 100): for _sev in range(-300, 301, 100):
...@@ -158,7 +171,8 @@ formatters = { ...@@ -158,7 +171,8 @@ formatters = {
def initialize_from_environment(): def initialize_from_environment():
""" Reinitialize the event logger from the environment """ """ Reinitialize the event logger from the environment """
# clear the current handlers from the event logger # clear the current handlers from the event logger
event_logger.logger.handlers = [] for h in event_logger.logger.handlers[:]:
event_logger.logger.removeHandler(h)
handlers = [] handlers = []
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
abstract section type. abstract section type.
</description> </description>
<key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/> <key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/>
<key name="level" default="info" datatype=".logging_level"/> <key name="level" default="notset" datatype=".logging_level"/>
</sectiontype> </sectiontype>
<sectiontype name="logfile" datatype=".FileHandlerFactory" <sectiontype name="logfile" datatype=".FileHandlerFactory"
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
<sectiontype name="eventlog" datatype=".EventLogFactory"> <sectiontype name="eventlog" datatype=".EventLogFactory">
<key name="level" datatype=".logging_level" default="all"/> <key name="level" datatype=".logging_level" default="info"/>
<multisection type="loghandler" attribute="handlers" name="*"/> <multisection type="loghandler" attribute="handlers" name="*"/>
</sectiontype> </sectiontype>
......
...@@ -25,9 +25,13 @@ _logging_levels = { ...@@ -25,9 +25,13 @@ _logging_levels = {
"fatal": 50, "fatal": 50,
"error": 40, "error": 40,
"warn": 30, "warn": 30,
"warning": 30,
"info": 20, "info": 20,
"blather": 15,
"debug": 10, "debug": 10,
"all": 0, "trace": 5,
"all": 1,
"notset": 0,
} }
def logging_level(value): def logging_level(value):
......
...@@ -172,7 +172,7 @@ class TestzLOGConfig(unittest.TestCase): ...@@ -172,7 +172,7 @@ class TestzLOGConfig(unittest.TestCase):
# XXX The "url" attribute of the handler is misnamed; it # XXX The "url" attribute of the handler is misnamed; it
# really means just the selector portion of the URL. # really means just the selector portion of the URL.
self.assertEqual(handler.url, "/log/") self.assertEqual(handler.url, "/log/")
self.assertEqual(handler.level, logging.INFO) self.assertEqual(handler.level, logging.NOTSET)
self.assertEqual(handler.method, "GET") self.assertEqual(handler.method, "GET")
self.assert_(isinstance(handler, zLOG.LogHandlers.HTTPHandler)) self.assert_(isinstance(handler, zLOG.LogHandlers.HTTPHandler))
...@@ -191,7 +191,7 @@ class TestzLOGConfig(unittest.TestCase): ...@@ -191,7 +191,7 @@ class TestzLOGConfig(unittest.TestCase):
self.assertEqual(handler.fromaddr, "zlog-user@example.com") self.assertEqual(handler.fromaddr, "zlog-user@example.com")
self.assertEqual(handler.level, logging.FATAL) self.assertEqual(handler.level, logging.FATAL)
def check_simple_logger(self, text, level=logging.NOTSET): def check_simple_logger(self, text, level=logging.INFO):
conf = self.get_config(text) conf = self.get_config(text)
self.assert_(conf.eventlog is not None) self.assert_(conf.eventlog is not None)
self.assertEqual(conf.eventlog.level, level) self.assertEqual(conf.eventlog.level, level)
......
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