Skip to main content
Solved

PythonCaller - Logging in FME Desktop 2015

  • February 29, 2016
  • 14 replies
  • 247 views

Forum|alt.badge.img

Hi everyone, 

I use the PythonCaller Transformer to validate data and want to write the errors to the log file. I already read the Article Logging with Python scripts and tried the example, but its not working. 

logger = fmeobjects.FMELogFile()
logger.logMessageString("...")

doesn't do anything ... 

I also tried 

def processFeature(feature):   
logger = open(FME_LogFileName,'a')
logger.write("test" +  "\n")

but its quite the same. 

Does someone know how to log via pythoncaller in FME Desktop 2015?

thanks,

Mel

Best answer by david_r

To log errors, specify the message severity in the call to logMessageString, e.g.

logger.logMessageString("Hello I am Logging Now", fmeobjects.FME_ERROR)

See also the fmeobjetcs API reference, under FMELogFile() for possible severity values.

David

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.

14 replies

david_r
Celebrity
  • February 29, 2016

Hi

The FME log file is already open when the PythonCaller is running, so you do not have to reopen it, you can simply call the FMELogFile() methods. This works:

import fmeobjects
def FeatureProcessor(feature):
    logger = fmeobjects.FMELogFile()
    logger.logMessageString('Hello world!')

Remember to specify "FeatureProcessor" as the entry point in the PythonCaller.

David


Forum|alt.badge.img
  • February 29, 2016

Your first code sample should work. Can you attach a sample not working workspace to your question? If no feature is going through your PythonCaller, I guess this is normal that nothing gets logged.


Forum|alt.badge.img
  • Author
  • February 29, 2016

Hi

The FME log file is already open when the PythonCaller is running, so you do not have to reopen it, you can simply call the FMELogFile() methods. This works:

import fmeobjects
def FeatureProcessor(feature):
    logger = fmeobjects.FMELogFile()
    logger.logMessageString('Hello world!')

Remember to specify "FeatureProcessor" as the entry point in the PythonCaller.

David

Thats what i already tried, 

import fmeobjects
def processFeature(feature):
logger = fmeobjects.FMELogFile()
logger.logMessageString("...")

I set the parameter "Class or Function to Process Features" to processFeature

(but its not working)

 


david_r
Celebrity
  • February 29, 2016

Thats what i already tried, 

import fmeobjects
def processFeature(feature):
logger = fmeobjects.FMELogFile()
logger.logMessageString("...")

I set the parameter "Class or Function to Process Features" to processFeature

(but its not working)

 

I just tested your code in FME 2015.1.3.1 and it works perfectly.

Have you searched your log file for "..." (hint: it will not appear at the end)? Do you get any error messages?

And, as Larry says above, make sure at least one feature goes into the PythonCaller, otherwise your code won't get executed.


Forum|alt.badge.img
  • Author
  • February 29, 2016

I just tested your code in FME 2015.1.3.1 and it works perfectly.

Have you searched your log file for "..." (hint: it will not appear at the end)? Do you get any error messages?

And, as Larry says above, make sure at least one feature goes into the PythonCaller, otherwise your code won't get executed.

Hm, no its not... Also in Brians (Article) example, when I remove the shutdown Python Script, the log File is empty, no "Hello I am Logging Now" is logged.

I am now using FME Desktpo 2015.1.0.0, I will try to update to the newest Version


Forum|alt.badge.img
  • Author
  • February 29, 2016

Your first code sample should work. Can you attach a sample not working workspace to your question? If no feature is going through your PythonCaller, I guess this is normal that nothing gets logged.

I tried the example from the article, the only thing that is working in this example is the logging inside the shutdown script. The Logging inside the PythonCaller is not, and the code is executing, at least I get my print messages. :/


david_r
Celebrity
  • February 29, 2016

Hm, no its not... Also in Brians (Article) example, when I remove the shutdown Python Script, the log File is empty, no "Hello I am Logging Now" is logged.

I am now using FME Desktpo 2015.1.0.0, I will try to update to the newest Version

Are you using a PythonCaller transformer or a shutdown script? Those are two fundamentally different things.

If you need to write to the FME log file from the shutdown script, you cannot use the FMELogFile() class, as the log file has already been closed at that time.

Try the following in your shutdown script:

logger = open(FME_LogFileName,'a')
logger.write("Hello world!\n")

The code I posted at the top of this thread will only work for a PythonCaller.


Forum|alt.badge.img
  • Author
  • February 29, 2016

@david_r

In my Workbench I am using a PythonCaller and a Python Shutdownscript, but only the PythonCaller doesn't log. (No matter what log methods)

I mentioned the shutdown script only because of the article, because thats the only logging that works


david_r
Celebrity
  • February 29, 2016

Can you post a sample workspace here? The PythonCaller code posted above should work.


Forum|alt.badge.img
  • Author
  • February 29, 2016

Can you post a sample workspace here? The PythonCaller code posted above should work.

logging2012woshutdownscript.fmw

Does create a Logging2012woShutdownscript.log file, but its empty.


david_r
Celebrity
  • February 29, 2016
logging2012woshutdownscript.fmw

Does create a Logging2012woShutdownscript.log file, but its empty.

Your workspace works perfectly here:

If you disable your PythonCaller, does your log file stay empty? What does the log window in FME Workbench say?

Do you have sufficient rights in the folder where your workspace is located?


Forum|alt.badge.img
  • Author
  • February 29, 2016

Your workspace works perfectly here:

If you disable your PythonCaller, does your log file stay empty? What does the log window in FME Workbench say?

Do you have sufficient rights in the folder where your workspace is located?

Ah, I see, I disabled "Log information" in the Log Filter, thats why the log file was empty. But I don't want to log to INFO level, is there a possibility to log an Error?

thanks for your help


david_r
Celebrity
  • Best Answer
  • February 29, 2016

To log errors, specify the message severity in the call to logMessageString, e.g.

logger.logMessageString("Hello I am Logging Now", fmeobjects.FME_ERROR)

See also the fmeobjetcs API reference, under FMELogFile() for possible severity values.

David


Forum|alt.badge.img
  • Author
  • February 29, 2016

To log errors, specify the message severity in the call to logMessageString, e.g.

logger.logMessageString("Hello I am Logging Now", fmeobjects.FME_ERROR)

See also the fmeobjetcs API reference, under FMELogFile() for possible severity values.

David

Thanks, it works now.