Search code examples
python-2.7openshifttailerror-logging

Does Python 2.7 write errors to a log file by default?


In OpenShift I am used to being able to view errors thrown by Python by using:

rhc tail -f app-root/logs/python.log [appname]

I have recently created a local development environment and want to be able to access the same functionality ie view any errors thrown by Python.

I can do this in regards to Apache errors:

sudo tail -100 /var/log/apache2/error.log

Is there something similar that can be viewed for errors in my Python application?

Environment

  • Linux Mint 17 Cinnamon
  • Python 2.7.6

UPDATE

Slight update to this scenario, I didn't note that I am using mod_wsgi which I now believe passes Python errors to the Apache log:

https://code.google.com/p/modwsgi/wiki/DebuggingTechniques

To get more detailed error messages, as the above document states, you can adjust the LogLevel setting in /etc/apache2/apache2.conf to:

LogLevel info

It seems to be catching errors such as when a function is called that has not been defined etc.

So, to my current understanding, it doesn't seem that recreating logging features within an application is necessary for my scenario.

[Thu Dec 04 13:00:44.899950 2014] [:error] [pid 6200] [client 127.0.0.1:48228] NameError: name 'undefined_function()' is not defined

Solution

  • No. Your logging on cloud services (whether from Apache or other tools) is a configuration of your server environment. If you've moved to a local environment that does not automatically support that, you won't have it.

    Python does have a logging module (which is rather complete and fairly complex), but it is an infrastructure for programs logging to files (or other destinations). It is not an automatic funneling of all your Python errors to a designated log file. Generally, Python error messages (sys.stderr) appear on your console in which you ran the program (or in your debugging console, if you from from within an IDE).