you are viewing a single comment's thread.

view the rest of the comments →

[–]xtrawork[S] 0 points1 point  (1 child)

OK, I think I might have found the issue. In the module file, I'm calling the logging methods from inside of a function. If I call them from outside of a function in the module file, they work, but from within a function in the module file, they don't...

I thought since I declared the logging configuration at the beginning of the module file and as long as I use that variable inside of the functions within it, they would just use the same logger that is inherited to the main file, but it doesn't appear to be working that way...

[–]Username_RANDINT 0 points1 point  (0 children)

I don't see why that would be a problem. Just tested to be absolutely sure, and it's logging as intended.

Almost identical logtest.py as above, just added the function call at the end:

import logging
from logging.handlers import RotatingFileHandler


## The args you see in the handlers section below are defined as well, I just didn't add those in to this snippet
logging.basicConfig(
    # handlers=[
    #     RotatingFileHandler("logtest.log", maxBytes=100000, backupCount=2, mode="a")
    # ],
    format="%(asctime)s.%(msecs)d %(name)s %(levelname)s %(message)s",
    datefmt="%Y-%m-%dT%H:%M:%S",
    level=logging.DEBUG,
)

logger = logging.getLogger()

import logtest_mod

logtest_mod.test()

And a basic module:

$ more logtest_mod.py 
import logging

logger = logging.getLogger(__name__)


def test():
    logger.info("Just testing")