r/learnpython • u/MezzoScettico • 2h ago
Can logging replace my verbosity controls?
An old habit from C days is to add print statements for debug and assign them different verbosity levels. I've been doing that in Python as well.
if verbosity > 2:
print("This level generates a lot of output, so use it sparingly")I've been told that the logging facility is the Python way to do this, so I'm finally investigating it. What I'm seeing is that the levels are DEBUG, INFO, WARNING, ERROR which doesn't really fit what I want to happen. Everything I want to put under verbosity control is technically DEBUG or INFO.
So my question is: are there sublevels on the DEBUG or INFO logging? Or is there another approach for this sort of thing?
EDIT: Still reading. I think the answer might be a hierarchy of loggers and filters? Trying to figure out how that works now.
View all comments
Show parent comment
2
u/MezzoScettico 2h ago
My desire is that INFO subdivides into INFO1, INFO2, INFO3, etc and that INFO, DEBUG, WARN was not enough granularity.
OK, but what if I don't want all the INFO messages? Sometimes I want only the higher level, sometimes I want really verbose detail. I typically have at least 0-2, and often more.
I know, I know. RTFM. I'm reading, still trying to absorb the model. Another answer says that there are actually level numbers and they are a lot finer granularity. Maybe that's the answer.
The multiple-logger thing seems like a powerful mechanism and I think that's what I really want to understand. It's overkill for what I'm trying to do today but I'm trying to practice with some baby code to figure it out.