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

Hi

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 !

image

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.logger.setLevel(logging.DEBUG)
        self.file_handler = logging.FileHandler('snap.log')
        self.file_handler.setLevel(logging.DEBUG)
        self.formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        self.file_handler.setFormatter(self.formatter)
        self.logger.addHandler(self.file_handler)
        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(['http://xxx.xxx.xxx.1', 'http://xxx.xxx.xxx.2'], port=9200, timeout=3600)

   try:
      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)
      snap_indicies.do_action()

      get_snapshot_state = snap_indicies.get_state()
      if get_snapshot_state == 'SUCCESS':
           elg.info('Successfully Created the Snapshot')
      else:
           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')
logger.setLevel(logging.DEBUG)
file_handler = logging.FileHandler('snap.log')
file_handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(self.formatter)
logger.addHandler(self.file_handler)

indices_list = [2000]

for indice in indices_list:
   REPOSITORY = 'index_backup'
…
        if get_snapshot_state == 'SUCCESS':
            logger.info('Successfully Created the Snapshot')
…

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.