[Python] How can I log the package name in Python?

Discussão em 'Python' iniciado por Stack, Julho 27, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using Pythons logging module. I want to log the full path of a message, like
    "msg packagename.modulename.functionName lineNumber", but how can I get the package name of a message?

    The logging configuration is:

    LOGGING = {
    'formatters': {
    'simple': {
    'format': '[%(levelname)s] %(message)s [%(module)s %(funcName)s %(lineno)d]'
    },
    },
    'handlers': {
    'console': {
    'level':'INFO',
    'class':'logging.StreamHandler',
    'formatter':'simple',
    }
    },
    'loggers': {
    'develop': {
    'handlers': ['console'],
    'level': 'DEBUG',
    'propagate': True,
    },
    }


    }

    and I get a logger like this:

    logger = logging.getLogger('develop')

    Continue reading...

Compartilhe esta Página