Python - Will logging happen if I don't import logging module

Viewed 42

When debugging a python function, I set up my logging like this:

import logging
logger_name = 'test.log'
log_format = "%(funcName)s:%(lineno)d -%(message)s"
logging.basicConfig(filename=logger_name,
                    level=logging.DEBUG,
                    format = log_format, 
                    filemode='w')

My program consists of multiple functions that are located in separate files, so I get the logger object at each file where I take functions from using the following:

import logging
logger = logging.getLogger(__name__)

However, when executing the function for finding out its execution time, I do not want to include my logs. Is it enough to just remove the set up of logging in the file where the main function is located? Or should I also remove logger = logging.getLogger(__name__) from each file, or should I do something else?

1 Answers

The logger main idea beside logging useful information to your console or file is to disable certains level of log easily.

To disable only the debug logging just set the level=logging.DEBUGto level=logging.INFO or level=logging.WARNING.

In that way your are keeping your log to warning when in production, and if you want to use debug, reverse it back

Related