Skip to main content

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

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


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.


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)

 


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.


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


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. :/


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.


@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


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


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.


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?


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


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


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.


Reply