-
Notifications
You must be signed in to change notification settings - Fork 168
Open
Description
Hi folks. I'm a big fan of this library! But I always end up creating something to store the log levels in a reliable way. I'd like to write code like this, using a clear class offering autocomplete (potentially docstrings, etc):
Then we can use it like:
logbook.StreamHandler(sys.stdout, level=LogLevel.debug).push_application()And the LogLevel class is a collection like this with a nice parse option for verification and canonicalization (e.g. "error " --> "ERROR"):
class LogLevel:
debug = "DEBUG"
info = "INFO"
notice = "NOTICE"
warning = "WARNING"
error = "ERROR"
critical = "CRITICAL"
@staticmethod
def parse(level_text: str) -> str:
if not level_text:
raise Exception("Level text must be specified")
level_text = level_text.upper().strip()
if level_text == LogLevel.debug:
return LogLevel.debug
elif level_text == LogLevel.info:
return LogLevel.info
elif level_text == LogLevel.notice:
return LogLevel.notice
elif level_text == LogLevel.warning:
return LogLevel.warning
elif level_text == LogLevel.error:
return LogLevel.error
elif level_text == LogLevel.critical:
return LogLevel.critical
else:
raise Exception(f"The level text {level_text} is not a supported log level.")Would you be willing to adopt something like this?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
