Commit 9225e2d8 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 6736b8bc
......@@ -25,6 +25,12 @@ from BaseLogger import BaseLogger
from LogHandlers import FileHandler, NullHandler, SysLogHandler
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):
# Get our logger object:
......@@ -82,23 +88,30 @@ def zlog_to_pep282_severity(zlog_severity):
zLOG severity PEP282 severity
------------- ---------------
PANIC (300) critical (50)
ERROR (200), PROBLEM (100) error (40)
INFO (0) warn (30)
BLATHER (-100) info (20)
DEBUG (-200), TRACE (-300) debug (10)
PANIC (300) FATAL, CRITICAL (50)
ERROR (200) ERROR (40)
WARNING, PROBLEM (100) WARN (30)
INFO (0) INFO (20)
BLATHER (-100) BLATHER (15) [*]
DEBUG (-200) DEBUG (10)
TRACE (-300) TRACE (5) [*]
[*] BLATHER and TRACE are custom logging levels.
"""
sev = zlog_severity
if sev >= 300:
return logging.CRITICAL
if sev >= 100:
return logging.FATAL
if sev >= 200:
return logging.ERROR
if sev >= 0:
if sev >= 100:
return logging.WARN
if sev >= -100:
if sev >= 0:
return logging.INFO
else:
if sev >= -100:
return CUSTOM_BLATHER
if sev >= -200:
return logging.DEBUG
return CUSTOM_TRACE
zlog_to_pep282_severity_cache = {}
for _sev in range(-300, 301, 100):
......@@ -158,7 +171,8 @@ formatters = {
def initialize_from_environment():
""" Reinitialize the event logger from the environment """
# 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 = []
......
......@@ -9,7 +9,7 @@
abstract section type.
</description>
<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 name="logfile" datatype=".FileHandlerFactory"
......@@ -54,7 +54,7 @@
<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="*"/>
</sectiontype>
......
......@@ -25,9 +25,13 @@ _logging_levels = {
"fatal": 50,
"error": 40,
"warn": 30,
"warning": 30,
"info": 20,
"blather": 15,
"debug": 10,
"all": 0,
"trace": 5,
"all": 1,
"notset": 0,
}
def logging_level(value):
......
......@@ -172,7 +172,7 @@ class TestzLOGConfig(unittest.TestCase):
# XXX The "url" attribute of the handler is misnamed; it
# really means just the selector portion of the URL.
self.assertEqual(handler.url, "/log/")
self.assertEqual(handler.level, logging.INFO)
self.assertEqual(handler.level, logging.NOTSET)
self.assertEqual(handler.method, "GET")
self.assert_(isinstance(handler, zLOG.LogHandlers.HTTPHandler))
......@@ -191,7 +191,7 @@ class TestzLOGConfig(unittest.TestCase):
self.assertEqual(handler.fromaddr, "zlog-user@example.com")
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)
self.assert_(conf.eventlog is not None)
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