title: Where can I find Celery logs in Flask?
body: <p>I'm working on a simple web app that runs a python script which can take about 5-10 minutes. Instead of making the user wait on the site, I run the job in the background using Celery and send the user an email notification when the script is complete.</p>
  
  <p>My question is straightforward: where are the logs for Celery job? Currently, if the job fails because it runs into a fatal error, I don't have any way of knowing.</p>
  
  <p>The <a href="http://docs.celeryproject.org/en/master/userguide/tasks.html?highlight=logging#logging" rel="noreferrer">Celery Logging Docs</a> show how to set up the logs, but it's not entirely clear to me where I can access the logs (I want to save as a file) after the job is complete.</p>
  
  <p>app.py</p>
  
  <pre><code>#----------------------------------------------------------------------------#
  # Imports
  #----------------------------------------------------------------------------#
  
  from flask import Flask, render_template, request, flash, send_file, redirect, url_for    
  from werkzeug import secure_filename
  import logging
  from logging import Formatter, FileHandler
  from forms import *
  
  import my_module
  from tasks import make_celery
  from celery.utils.log import get_task_logger
  
  
  #----------------------------------------------------------------------------#
  # App Config.
  #----------------------------------------------------------------------------#
  
  app = Flask(__name__)
  app.config.from_object('config')
  
  celery = make_celery(app)
  logger = get_task_logger(__name__)
  
  format = "%(asctime)s - [%(levelname)s] %(message)s"
  logging.basicConfig(filename='app-errors.log', 
                      filemode='a',
                      format=format,
                      level=logging.DEBUG)
  console = logging.StreamHandler()
  console.setLevel(logging.DEBUG)
  logging.getLogger(__name__).addHandler(console)
  
  #----------------------------------------------------------------------------#
  # Controllers.
  #----------------------------------------------------------------------------#
  
  @celery.task
  def background_task(formdict):
      logger.debug('starting work...')
      result = my_module.main(formdict)
      return result
  
  @app.route('/', methods=('GET', 'POST'))
  def index():
      form = MyForm()
      if form.validate_on_submit():
          task = background_task.delay(form.data)
  
          return redirect(url_for('jobcomplete'))
      else:
          print form.errors
          filename = None
      return render_template('pages/home.html', form=form)
  </code></pre>