Commit f80a5e0b authored by Fred Drake's avatar Fred Drake

Revert zLOG changes that proved to be contentious.

parent 88ebcd9b
...@@ -11,10 +11,9 @@ ...@@ -11,10 +11,9 @@
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
__version__='$Revision: 1.20 $'[11:-2] __version__='$Revision: 1.21 $'[11:-2]
import os, sys, time import os, sys, time
import zLOG
try: try:
import textwrap import textwrap
...@@ -54,39 +53,7 @@ class stupid_log_write: ...@@ -54,39 +53,7 @@ class stupid_log_write:
self.initialize() self.initialize()
def initialize(self): def initialize(self):
path, severity = self.get_environment_info()
self.initialize_log(path, severity)
def initialize_with_config(self, config):
"""Initialize logging with information from ZConfig."""
path, severity = self.get_environment_info()
if config is not None:
loginfo = config.getSection("log")
if loginfo is not None:
if path is None:
path = loginfo.get("path")
if severity is None:
severity = loginfo.get("level")
self.initialize_log(path, severity)
def initialize_log(self, path, severity):
global _log_level global _log_level
if path is None:
_set_log_dest(None)
elif path:
_set_log_dest(open(path, 'a'))
else:
_set_log_dest(sys.stderr)
if severity:
_log_level = zLOG.severity(severity)
else:
_log_level = 0 # INFO
def get_environment_info(self):
eget = os.environ.get eget = os.environ.get
# EVENT_LOG_FILE is the preferred envvar, but we accept # EVENT_LOG_FILE is the preferred envvar, but we accept
...@@ -94,14 +61,21 @@ class stupid_log_write: ...@@ -94,14 +61,21 @@ class stupid_log_write:
path = eget('EVENT_LOG_FILE') path = eget('EVENT_LOG_FILE')
if path is None: if path is None:
path = eget('STUPID_LOG_FILE') path = eget('STUPID_LOG_FILE')
if path is None:
_set_log_dest(None)
else:
if path:
_set_log_dest(open(path, 'a'))
else:
_set_log_dest(sys.stderr)
# EVENT_LOG_SEVERITY is the preferred envvar, but we accept # EVENT_LOG_SEVERITY is the preferred envvar, but we accept
# STUPID_LOG_SEVERITY also # STUPID_LOG_SEVERITY also
severity = eget('EVENT_LOG_SEVERITY') severity = eget('EVENT_LOG_SEVERITY') or eget('STUPID_LOG_SEVERITY')
if severity is None: if severity:
severity = eget('STUPID_LOG_SEVERITY') _log_level = int(severity)
else:
return path, severity _log_level = 0 # INFO
def log(self, subsystem, severity, summary, detail, error): def log(self, subsystem, severity, summary, detail, error):
if _log_dest is None or severity < _log_level: if _log_dest is None or severity < _log_level:
...@@ -138,4 +112,3 @@ class stupid_log_write: ...@@ -138,4 +112,3 @@ class stupid_log_write:
_log = stupid_log_write() _log = stupid_log_write()
log_write = _log.log log_write = _log.log
initialize = _log.initialize initialize = _log.initialize
initialize_with_config = _log.initialize_with_config
...@@ -86,10 +86,10 @@ There is a default event logging facility that: ...@@ -86,10 +86,10 @@ There is a default event logging facility that:
can be overridden with the environment variable EVENT_LOG_SEVERITY can be overridden with the environment variable EVENT_LOG_SEVERITY
""" """
__version__='$Revision: 1.11 $'[11:-2] __version__='$Revision: 1.12 $'[11:-2]
from MinimalLogger import log_write, log_time, severity_string, \ from MinimalLogger import log_write, log_time, severity_string, \
_set_log_dest, initialize, initialize_with_config _set_log_dest, initialize
from traceback import format_exception from traceback import format_exception
# Standard severities # Standard severities
...@@ -102,30 +102,6 @@ WARNING = 100 ...@@ -102,30 +102,6 @@ WARNING = 100
ERROR = 200 ERROR = 200
PANIC = 300 PANIC = 300
_severity_names = {"trace": -300,
"debug": -200,
"blather": -100,
"info": 0,
"problem": 100,
"warning": 100,
"error": 200,
"panic": 300,
}
def severity(value):
"""Return the severity level associated with a value.
The value may be an integer, the repr of an integer, or the name
of a well-known severity value (case-insensitive).
"""
try:
return int(value)
except ValueError:
try:
return _severity_names[value.lower()]
except KeyError:
raise ValueError("unknown severity value: " + repr(value))
def LOG(subsystem, severity, summary, detail='', error=None, reraise=None): def LOG(subsystem, severity, summary, detail='', error=None, reraise=None):
"""Log some information """Log some information
......
...@@ -16,10 +16,6 @@ import os ...@@ -16,10 +16,6 @@ import os
import sys import sys
import tempfile import tempfile
import unittest import unittest
from cStringIO import StringIO
import ZConfig
import zLOG import zLOG
severity_string = { severity_string = {
...@@ -64,7 +60,7 @@ class StupidLogTest(unittest.TestCase): ...@@ -64,7 +60,7 @@ class StupidLogTest(unittest.TestCase):
def setLog(self, severity=0): def setLog(self, severity=0):
os.environ['%s_LOG_FILE' % self.prefix] = self.path os.environ['%s_LOG_FILE' % self.prefix] = self.path
if severity is not None: if severity:
os.environ['%s_LOG_SEVERITY' % self.prefix] = str(severity) os.environ['%s_LOG_SEVERITY' % self.prefix] = str(severity)
self._severity = severity self._severity = severity
zLOG.MinimalLogger._log.initialize() zLOG.MinimalLogger._log.initialize()
...@@ -111,19 +107,13 @@ class StupidLogTest(unittest.TestCase): ...@@ -111,19 +107,13 @@ class StupidLogTest(unittest.TestCase):
def getLogFile(self): def getLogFile(self):
return open(self.path, 'rb') return open(self.path, 'rb')
def checkBasics(self, severity=None): def checkBasics(self):
self.setLog(severity=severity) self.setLog()
zLOG.LOG("basic", zLOG.INFO, "summary") zLOG.LOG("basic", zLOG.INFO, "summary")
f = self.getLogFile() f = self.getLogFile()
self.verifyEntry(f, subsys="basic", summary="summary") self.verifyEntry(f, subsys="basic", summary="summary")
def checkBasicsNumericSeverity(self):
self.checkBasics(severity=0)
def checkBasicsNamedSeverity(self):
self.checkBasics(severity='info')
def checkDetail(self): def checkDetail(self):
self.setLog() self.setLog()
zLOG.LOG("basic", zLOG.INFO, "xxx", "this is a detail") zLOG.LOG("basic", zLOG.INFO, "xxx", "this is a detail")
...@@ -150,24 +140,9 @@ class EventLogTest(StupidLogTest): ...@@ -150,24 +140,9 @@ class EventLogTest(StupidLogTest):
""" Test alternate envvars EVENT_LOG_FILE and EVENT_LOG_SEVERITY """ """ Test alternate envvars EVENT_LOG_FILE and EVENT_LOG_SEVERITY """
prefix = 'EVENT' prefix = 'EVENT'
class ConfigLogTest(StupidLogTest):
""" Test using a ZConfig section to control logging. """
def setLog(self, severity=None):
self._severity = severity
text = "<Log>\n path %s \n" % self.path
if severity is not None:
text += " level %s \n" % severity
text += "</Log>"
sio = StringIO(text)
conf = ZConfig.loadfile(sio)
zLOG.MinimalLogger._log.initialize_with_config(conf)
def test_suite(): def test_suite():
suite = unittest.makeSuite(StupidLogTest, 'check') suite = unittest.makeSuite(StupidLogTest, 'check')
suite.addTest(unittest.makeSuite(EventLogTest, 'check')) suite.addTest(unittest.makeSuite(EventLogTest, 'check'))
suite.addTest(unittest.makeSuite(ConfigLogTest, 'check'))
return suite return suite
if __name__ == "__main__": if __name__ == "__main__":
......
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