Question

How to write a python script to log FME error to the database if the FME Workspace fails?

  • 10 March 2016
  • 1 reply
  • 4 views

Badge

vani.sm@techmahindra.com


1 reply

Userlevel 4

Hi

Using this pattern you can catch any error messages sent to the log window and access them in your shutdown script, e.g. for writing them to a database or a separate log file:

In the startup script we define a global list "my_fme_messages" and we tell FME to add all log file messages with a severity of WARN, ERROR or FATAL to it:

from fmeobjects import *
global my_fme_messages
my_fme_messages = []

def LogSkimmer(severity, text):
    if severity in (FME_WARN, FME_ERROR, FME_FATAL):
        my_fme_messages.append(text)
 
FMELogFile().setCallBack(LogSkimmer)

In the shutdown script, we can then analyse "my_fme_messages" and do whatever we want with it:

import fme
if not fme.status:
    # Translation failed
    global my_fme_messages
    for msg in my_fme_messages:
        # Do something with the error message(s)
        print "Message was:", msg

David

Reply