I have been struggling a lot with printing Debug statements to console (+ to a file) and info just to the file. It's a big module and I am passing logger objects created in main file to all others in the function calls.
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', datefmt='%Y%m%d %H:%M', filename='full_log.log', filemode='w') console = logging.StreamHandler() formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') console.setFormatter(formatter) console.setLevel(logging.DEBUG) logging.getLogger('').addHandler(console) logger_1 = logging.getLogger('logger_1') logger_module = logging.getLogger('module') logger_1.debug("sample debug") logger_1.info("sample info") fil.main(logger_module) test/fil.py
def main(logger): logger.info("Hello logging!") Both info and debug prints to console and writes to the file too. Can someone please explain what am I doing wrong? How do I set levels to print and write to file?