r/learnpython • u/MezzoScettico • 3h 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
•
u/Outside_Complaint755 22m ago
Instead of sending all messages to the terminal, send the logging output to a file, and then you can use Ctrl+F to search the file for whatever specific message you are looking for. You can then include keys to search for (I1, I2, etc) in the log messages instead of trying to insert a dozen custom logging levels.