Refactored LogLevel crap.

This commit is contained in:
Jeremy Fincher 2004-04-18 06:24:37 +00:00
parent 437afe707c
commit 086a2fcab6
2 changed files with 18 additions and 21 deletions

View File

@ -130,24 +130,12 @@ _formatString = '%(name)s: %(levelname)s %(message)s'
_ircFormatter = ColorizedIrcFormatter(_formatString)
_ircHandler.setFormatter(_ircFormatter)
class IrcLogLevel(log.LogLevel):
class IrcLogLevel(log.ValidLogLevel):
"""Value must be one of INFO, WARNING, ERROR, or CRITICAL."""
def set(self, s):
# FIXME: Overriding set() here because log.LogLevel.set() sets the
# default log level as well. log.LogLevel and this class should be
# refactored and use registry.OnlySomeStrings in the future.
s = s.upper()
try:
self.setValue(getattr(logging, s))
_ircHandler.setLevel(self.value)
except AttributeError:
self.error()
minimumLevel = logging.INFO
def setValue(self, v):
if v <= logging.DEBUG:
self.error()
else:
log.LogLevel.setValue(self, v)
log.ValidLogLevel.setValue(self, v)
_ircHandler.setLevel(self.value)
class ValidChannelOrNick(registry.String):
"""Value must be a valid channel or a valid nick."""

View File

@ -220,20 +220,29 @@ class MetaFirewall(type):
return type.__new__(cls, name, bases, dict)
class LogLevel(registry.Value):
"""Invalid log level. Value must be either DEBUG, INFO, WARNING, ERROR,
or CRITICAL."""
class ValidLogLevel(registry.String):
"""This should be overridden."""
minimumLevel = -1
def set(self, s):
s = s.upper()
try:
self.setValue(getattr(logging, s))
_logger.setLevel(self.value) # _logger defined later.
level = getattr(logging, s)
if level < self.minimumLevel:
self.error()
self.setValue(level)
except AttributeError:
self.error()
def __str__(self):
return logging.getLevelName(self.value)
class LogLevel(ValidLogLevel):
"""Invalid log level. Value must be either DEBUG, INFO, WARNING, ERROR,
or CRITICAL."""
def setValue(self, v):
ValidLogLevel.setValue(self, v)
_logger.setLevel(self.value) # _logger defined later.
conf.supybot.directories.register('log', registry.String('logs', """Determines
what directory the bot will store its logfiles in."""))