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!
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With