mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 20:52:42 +01:00
Allow numeric levels as well, so statistcs can be -1 if necessary.
This commit is contained in:
parent
275ba6502c
commit
24e09136b6
15
src/log.py
15
src/log.py
@ -249,20 +249,25 @@ class MetaFirewall(type):
|
|||||||
|
|
||||||
|
|
||||||
class ValidLogLevel(registry.String):
|
class ValidLogLevel(registry.String):
|
||||||
"""This should be overridden."""
|
"""Invalid log level."""
|
||||||
minimumLevel = -1
|
minimumLevel = -1
|
||||||
def set(self, s):
|
def set(self, s):
|
||||||
s = s.upper()
|
s = s.upper()
|
||||||
try:
|
try:
|
||||||
level = getattr(logging, s)
|
level = getattr(logging, s)
|
||||||
if level < self.minimumLevel:
|
|
||||||
self.error()
|
|
||||||
self.setValue(level)
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
try:
|
||||||
|
level = int(s)
|
||||||
|
except ValueError:
|
||||||
|
self.error()
|
||||||
|
if level < self.minimumLevel:
|
||||||
self.error()
|
self.error()
|
||||||
|
self.setValue(level)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return logging.getLevelName(self.value)
|
level = logging.getLevelName(self.value)
|
||||||
|
if level.startswith('Level'):
|
||||||
|
level = level.split()[-1]
|
||||||
|
|
||||||
class LogLevel(ValidLogLevel):
|
class LogLevel(ValidLogLevel):
|
||||||
"""Invalid log level. Value must be either DEBUG, INFO, WARNING, ERROR,
|
"""Invalid log level. Value must be either DEBUG, INFO, WARNING, ERROR,
|
||||||
|
Loading…
Reference in New Issue
Block a user