0

I want my code to only log debug level messages when some variable is set to true. Is it possible? Here is my config for the logging module. Right now, I have to comment and uncomment at different places in my code to enable or disable the logging...

formatter = logging.Formatter('%(asctime)s; %(levelname)s;\t %(message)s')
handler = logging.FileHandler('/mylog.log')
handler.setFormatter(formatter)
logger = logging.getLogger('')
logger.addHandler(handler)
logger.setLevel('DEBUG')

<then somewhere in my code>
logger.debug('some messages')

It would be even better if this variable can be an integer, and when set, only logger with level same or higher will function... Is it possible?

Thanks!

Difan Zhao
  • 379
  • 6
  • 20

1 Answers1

1

if my_var: logger.setLevel('Warning') check the doc

Benoît P
  • 3,179
  • 13
  • 31