I am using RotatingFilehandler to keep 5 files as backup. but it is not logging the messages from all the modules except the main module.
basicconfig is working but it creates only one file.
log_check.py :
import ll
import logChk
import logging
from logging.handlers import RotatingFileHandler
LOG_FILENAME = 'check.log'
logger = logging.getLogger(__name__)
formatter =logging.Formatter("[%(asctime)s] %(levelname)s [ %(name)s.%(funcName)s:%(lineno)d] - %(message)s")
logger.setLevel(logging.DEBUG)
handler = RotatingFileHandler(LOG_FILENAME, maxBytes=2000, backupCount=5)
handler.setFormatter(formatter)
logger.addHandler(handler)
logger = logging.getLogger(__name__)
def foo():
logger.warning("logging from d on call foo()")
if __name__ == "__main__":
logger.info('Starting logger for...')
logger.warning('logging from c')
foo()
logChk.doo()
ll.fun()
ll.py :
import logging
import log_conf
logger=logging.getLogger(__name__)
def fun():
logger.info("In Fun")
logChk.py :
import logging
logger = logging.getLogger(__name__)
def doo():
logger.info('Starting logger for... in dooo')
it is not logging the messages from all the modules except the main module.I do not see any reference to amainmodule in your code snippets here at time of writing. Can you add it or adjust your module names appropriately?disable_existing_loggersas well to see if this is what's getting you: docs.python.org/3.7/howto/logging.html#configuring-logging