We are running NiFi 1.8, trying to log to a rotating log file from a python
script executed by an ExecuteScript processor. We are seeing no output to
the log file.
I seem to be establishing the log file handler and the logger without any
errors.
I see the log file in my log output directory, so I know it gets created.
Can this approach be used from Execute Script? What am i neglecting?

My approach is as follows:

flowFiles = session.get(100)
for flowFile in flowFiles :
     if (flowFile != None) :
          fh =
logging.handlers.RotatingFileHandler('/opt/nifi/logs/myLog.log',
maxBytes=500000, backupCount=20)
          fh.setLevel(logging.DEBUG)
          formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s
%(message)s')
          fh.setFormatter(formatter)
          logger = logging.getLogger()
          logger.addHandler(fh)

          incoming = flowFile.getAttribute('filename)
          logger.info('about to process: %s', incoming)
          flowFile = session.write(flowFile, PyStreamCallback())   # heavy
lifting in this PyStreamCallback
          logger.info('completed processing: %s', incoming)

          fh.close()
          while logger.handlers :
               logger.handlers.pop()
          del fh

          session.transfer(flowFile, REL_SUCCESS)

Thanks in advance for your help. -Jim

Reply via email to