Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No handlers could be found for logger "elasticsearch.trace"

Updated: Turns out, this is not a function of cron. I get the same behavior when running the script from the command line, if it in fact has a record to process and communicates with ElasticSearch.


I have a cron job that runs a python script which uses pyelasticsearch to index some documents in an ElasticSearch instance. The script works fine from the command line, but when run via cron, it results in this error:

No handlers could be found for logger "elasticsearch.trace"

Clearly there's some logging configuration issue that only crops up when run under cron, but I'm not clear what it is. Any insight?

like image 554
Laizer Avatar asked Nov 24 '15 20:11

Laizer


1 Answers

I solved this by explicitly configuring a handler for the elasticsearch.trace logger, as I saw in examples from the pyelasticsearch repo.

After importing pyelasticsearch, set up a handler like so:

tracer = logging.getLogger('elasticsearch.trace')
tracer.setLevel(logging.INFO)
tracer.addHandler(logging.FileHandler('/tmp/es_trace.log'))

I'm not interested in keeping the trace logs, so I used the near-at-hand Django NullHandler.

from django.utils.log import NullHandler
tracer = logging.getLogger('elasticsearch.trace')
tracer.setLevel(logging.INFO)
tracer.addHandler(NullHandler())
like image 152
Laizer Avatar answered Oct 12 '22 19:10

Laizer