mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-02 17:29:22 +01:00
Refactored LogLevel crap.
This commit is contained in:
parent
437afe707c
commit
086a2fcab6
@ -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."""
|
||||
|
19
src/log.py
19
src/log.py
@ -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."""))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user