title: How to write console output to text file in Flask?
body: <p>I am using Ubuntu, python3 and Flask server.
  I simply want the line  print('**found file', file.filename, '\n') which is printed on terminal to be saved into a text file.</p>
  
  <p>Any kind of help would be appreciated. Thanks in advance. </p>
  
  <pre><code>import os
  from flask import Flask, request, redirect, url_for, send_from_directory, jsonify
  from werkzeug import secure_filename
  
  UPLOAD_FOLDER = 'uploads'
  ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'mp4'])
  
  app = Flask(__name__)
  app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
  
  def allowed_file(filename):
    # this has changed from the original example because the original did not work for me
      return filename[-3:].lower() in ALLOWED_EXTENSIONS
  
  @app.route('/', methods=['GET', 'POST'])
  def upload_file():
      if request.method == 'POST':
          file = request.files['file']
          if file and allowed_file(file.filename):
              print('**found file', file.filename, '\n')
              filename = secure_filename(file.filename)
              file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
              return jsonify({"success" : url_for('uploaded_file',
                                      filename=filename)})
      return '''
      &lt;!doctype html&gt;
      &lt;title&gt;Upload new File&lt;/title&gt;
      &lt;h1&gt;Upload new File&lt;/h1&gt;
      &lt;form action="" method=post enctype=multipart/form-data&gt;
        &lt;p&gt;&lt;input type=file name=file&gt;
           &lt;input type=submit value=Upload&gt;
      &lt;/form&gt;
      '''
  
  @app.route('/uploads/&lt;filename&gt;')
  def uploaded_file(filename):
      return send_from_directory(app.config['UPLOAD_FOLDER'],
                                 filename)
  
  if __name__ == '__main__':
      app.run(host= '0.0.0.0', debug=True)
  </code></pre>