0

Is it possible and what would be the best way to cancel some log entries added via log.debug() after they were added?

I'm trying to not log anything if nothing noteworthy happened in my application (which I only know by the end of my main() loop).

user182917
  • 1,688
  • 2
  • 14
  • 17
  • 1
    Why don't you use what is provided in the Log documentation by assigning different levels to your logging and modify your logging accordingly so you only log out based on severity. https://docs.python.org/2/library/logging.html#levels – idjaw Feb 23 '16 at 19:53
  • You could just store pending messages on a list, then send them all at once when you feel the need – salezica Feb 23 '16 at 19:53
  • @idjaw, because the severity of these logs are not different, in fact there are different severities mixed in these logs. I just want to cancel them out in case of 'empty' loops to preserve log space, only logging what's noteworthy. But I could extend this to all logs in the app. – user182917 Feb 23 '16 at 19:59
  • @slezica, if possible I wanted to do this inside the logging API, using filtering or a delayed writer or something like this. – user182917 Feb 23 '16 at 20:04
  • Possible duplicate of [How to I disable and re-enable console logging in Python?](http://stackoverflow.com/questions/2266646/how-to-i-disable-and-re-enable-console-logging-in-python) – dot.Py Feb 23 '16 at 20:20

1 Answers1

1

You can use this piece of code:

logger = logging.getLogger()

logger.disabled = True
## content that WON'T appear in your log file ##

logger.disabled = False
## content that WILL appear in your log file ##

You should take a look here. Maybe you'll find something useful.

Community
  • 1
  • 1
dot.Py
  • 5,007
  • 5
  • 31
  • 52