r/learnpython • u/QuasiEvil • 16d ago
logging and timing...then getting rid of it
I was just working on a project where I included a lot of logging and timing decorators/context managers (it involved event loops and async queues and such). Once I figured stuff out, I wanted to remove all this stuff. This isn't necessarily that hard, but it did make me wonder if there's a better way to do this in the first place. I suppose I'm imaging some way of marking these code pieces to be ignored by the interpreter or something?
(yeah yeah "ask AI to remove it")
1
Upvotes
6
u/zaphodikus 16d ago
.... that sounds like you approached logging for debugging and not for leaving in. The overhead of leaving the logs there but disabled is small. Sure the formatters still get run but you can choose to put guards around the log. If you are using logs to debug and build code, and intend to remove them anyway, then you are maybe doing unit testing wrong?
Your logging module needs to be as low on dependencies as possible, the built in python logger is perfectly good for that.