diff --git a/plugins/LogToIrc.py b/plugins/LogToIrc.py index 6480c8942..44bffaa72 100644 --- a/plugins/LogToIrc.py +++ b/plugins/LogToIrc.py @@ -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.""" diff --git a/src/log.py b/src/log.py index 82252fe2f..d445e8baf 100644 --- a/src/log.py +++ b/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."""))