No handlers could be found for logger "curator.actions.snapshot"


I am getting following error while I run a python script and the script failed to create the snapshot. How can I fix this

No handlers could be found for logger "curator.actions.snapshot"

NOTE: The python script use elasticsearch & curator libraries

This is a message telling you that Curator attempted to initiate logging, but could not find a logging handler. This does not mean that the script failed, but does indicate that you can't see what logs Curator would otherwise be showing you.

So How can I fix this. I used basic logging in my script and tried it.

But still I am getting same error !


following are my scripts

(1). EventLogger class

import logging

class EventLogger:

    def __init__(self):
        self.formatter = None
        self.logger = None
        self.file_handler = None
        self.logger_name = None

    def log_event(self):
        self.logger = logging.getLogger(__name__)
        self.file_handler = logging.FileHandler('snap.log')
        self.formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        return self.logger

(2). Creating snapshot

from elasticsearch import Elasticsearch
import curator
import eventlogger

el = eventlogger.EventLogger()
elg = el.log_event()

indices_list = [2000]

for indice in indices_list:
   REPOSITORY = 'index_backup'
   SOURCE = 'creation_date'
   DIRECTION = 'older'
   UNIT = 'days'
   UNIT_COUNT = 10
   INDEX_NAME = 'xxxxxxx_' + str(indice)

   es = Elasticsearch(['', ''], port=9200, timeout=3600)

      ilo = curator.IndexList(es)
      ilo.filter_by_age(source=SOURCE, direction=DIRECTION, unit=UNIT, unit_count=UNIT_COUNT)
      ilo.filter_by_regex(kind='prefix', value=INDEX_NAME)
      snap_indicies = curator.Snapshot(ilo, REPOSITORY, INDEX_NAME, skip_repo_fs_check=True)

      get_snapshot_state = snap_indicies.get_state()
      if get_snapshot_state == 'SUCCESS':
 'Successfully Created the Snapshot')
           elg.error('Failed to Create the Snapshot')
    except Exception as snapindicies:
      elg.error('Exception Occured Creating the Snapshot')

You've made your own logging event class, but not set up any local logging. Everything inside that elg is stuck in elg and will only log when you call something in elg. Curator won't know what to do with that.

Perhaps if you put the log_event method calls inside your primary script and declared a regular python logger, not your class, it would work:

from elasticsearch import Elasticsearch
import curator
import logging

logger = logging.getLogger('my_script')
file_handler = logging.FileHandler('snap.log')
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

indices_list = [2000]

for indice in indices_list:
   REPOSITORY = 'index_backup'
        if get_snapshot_state == 'SUCCESS':
  'Successfully Created the Snapshot')