[Python] Python error log location

Discussão em 'Python' iniciado por Stack, Dezembro 22, 2024.

  1. Stack

    Stack Membro Participativo

    I am developing a python application on flask framework. And I use .wsgi to deploy it. I got confused by error log locations. It looks like Python errors and debug information are put into different log files.

    First of all, I specify both access and error log locations in the apache vhost file.

    <VirtualHost *:myport>
    ...
    CustomLog /homedir/access.log common
    ErrorLog /homedir/error.log
    ...
    </VirtualHost>


    I also know there is another apache error log, /var/log/httpd/error_log. My access logs were printed into the right place, /homedir/access.log.

    But, error log looks weird. The Python errors, like SyntaxError, uncaught exceptions went to the log file specified in vhost file (/homedir/error.log). But, any log messages generated by python logging module, went to the "default" error log (/var/log/httpd/error_log).

    Can anyone explain why this is happening and how to fix it? I want these two logs go to the same place.


    Thanks for the comments. Here is the code I set up logger

    import logging

    # I didn't specify the stream, so it suppose to be stderr
    # Don't know why stderr points to apache /var/log/*, rather than my error log

    stream_handler = logging.StreamHandler()
    formatter = logging.Formatter("%(levelname)s : %(pathname)s:%(lineno)s - %(msg)s")
    stream_handler.setFormatter(formatter)

    logger = logging.getLogger('foo')
    logger.addHandler(stream_handler)
    logger.setLevel(logging.DEBUG)


    Then, I logged messages in this way.

    import logging
    logger = logging.getLogger('foo.bar')

    logger.debug('Some debug information')


    But, the log goes to /var/log/httpd/error_log, rather than the log specified in apache vhost file.

    Continue reading...

Compartilhe esta Página