Reputation: 54003
I just deployed the first website I built with Flask to a production server. I enabled logging using the logging.handlers.RotatingFileHandler
to /log/myapp.log
, with which I can log messages using for example:
current_app.logger.error('this is a massive error')
This works fine. It makes me wonder about some pieces of code though, which contain for example print 'some info here'
which I used while debugging. Where do these printouts go? Into the void /dev/null
or somewhere else? Is there a possibility to catch them somehow?
All tips are welcome!
Upvotes: 9
Views: 10146
Reputation: 4061
Print statements in app running on apache can be usually seen in the Apache logs. You can check this file: /var/log/apache2/other_vhosts_access.log
Upvotes: 2
Reputation: 37661
Everything you output using print
goes to the standard output, i.e. /dev/stdout
on a Unix server (by default). Since apache is running as a service, you will probably never see these output.
One way to deal with this is to redirect the standard output of your scripts to some files:
>>> import sys
>>> sys.stdout = open('output.logs', 'w')
>>> print('Hello World!') # Nothing appears bellow
>>> sys.stdout = sys.__stdout__ # Reset to the standard output
>>> open('output.logs', 'r').read()
'Hello World!\n'
Upvotes: 9