No handlers could be found for logger "apscheduler.executors.default"?

carbon_ghost picture carbon_ghost · Feb 25, 2015 · Viewed 11.8k times · Source

I have a python script being run via a nightly job on Heroku. Every once in a while (and lately, a lot more), the script fails to execute due to the below error.

2015-02-25T05:00:02.671242+00:00 app[clock.1]: No handlers could be found for logger "apscheduler.executors.default"

The script is executed using the inbuilt clock method as defined in my Procfile.

clock.py:

import sys
import logging

sys.path.append('main')

from main import main
from apscheduler.schedulers.blocking import BlockingScheduler

sched = BlockingScheduler()

# Executes every night at 5:00am UTC time | 12:00am (midnight) Winston-Salem, NC time
@sched.scheduled_job('cron', hour=5)
def scheduled_job():
    logging.basicConfig()
    main()

sched.start()

I've searched the web and based on the few responses I've read, people say this is a warning as opposed to an error. However, this problem causes the entire script to fail when it does happen. My question is first, is there a fix for this? And secondly, why does this happen sometimes and not always?

Lot's of people said to simply add the following to the script:

import logging
logging.basicConfig()

Which, as you can see, I did but the issue still persists.

Answer

iChux picture iChux · Mar 15, 2016
import logging

log = logging.getLogger('apscheduler.executors.default')
log.setLevel(logging.INFO)  # DEBUG

fmt = logging.Formatter('%(levelname)s:%(name)s:%(message)s')
h = logging.StreamHandler()
h.setFormatter(fmt)
log.addHandler(h)

I got mine working with a nice format like this