Skip to main content
Solved

Retriev errors

  • December 31, 2014
  • 1 reply
  • 7 views

farfar
Contributor
Forum|alt.badge.img+12
Hi all,

 

I've a workbench with one reader and one writer. if the traitment is issue i would retrieve the raisons or logs into file (my writer or another file).

 

Any idea?

 

Thanks an advance.

 

FarFar 

Best answer by takashi

Hi FarFar,

 

 

If you want to write only error messages into a file automatically, define a function to collect error messages in the Sartup Pytnon Script, and write the messages in the Shutdown Script. For example:

 

-----

 

# Startup Python Script

 

import fmeobjects

 

 

# Error message collector.

 

errorMessages = []

 

 

# Callback function

 

def collectErrorMessages(severity, message):

 

    if severity == fmeobjects.FME_ERROR or severity == fmeobjects.FME_FATAL:

 

        errorMessages.append(message)

 

 

# Set the function to the FME LogFile object

 

logFile = fmeobjects.FMELogFile()

 

logFile.setCallBack(collectErrorMessages)

 

logFile = None

 

-----

 

# Shutdown Python Script

 

if 0 < len(errorMessages):

 

    f = open('C:\\\\tmp\\\\error_log.txt', 'w')

 

    for msg in errorMessages:

 

        f.write('%s\\n' % msg)

 

    f.close()

 

-----

 

 

Takashi
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

1 reply

takashi
Celebrity
  • Best Answer
  • December 31, 2014
Hi FarFar,

 

 

If you want to write only error messages into a file automatically, define a function to collect error messages in the Sartup Pytnon Script, and write the messages in the Shutdown Script. For example:

 

-----

 

# Startup Python Script

 

import fmeobjects

 

 

# Error message collector.

 

errorMessages = []

 

 

# Callback function

 

def collectErrorMessages(severity, message):

 

    if severity == fmeobjects.FME_ERROR or severity == fmeobjects.FME_FATAL:

 

        errorMessages.append(message)

 

 

# Set the function to the FME LogFile object

 

logFile = fmeobjects.FMELogFile()

 

logFile.setCallBack(collectErrorMessages)

 

logFile = None

 

-----

 

# Shutdown Python Script

 

if 0 < len(errorMessages):

 

    f = open('C:\\\\tmp\\\\error_log.txt', 'w')

 

    for msg in errorMessages:

 

        f.write('%s\\n' % msg)

 

    f.close()

 

-----

 

 

Takashi