Skip to main content
Solved

PythonCaller - Logging in FME Desktop 2015


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

View original
Did this help you find an answer to your question?
This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, 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
Evangelist
  • 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
david_r wrote:

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
Evangelist
  • February 29, 2016
me1 wrote:

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
david_r wrote:

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
larry wrote:

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
Evangelist
  • February 29, 2016
me1 wrote:

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
Evangelist
  • 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
david_r wrote:

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
Evangelist
  • February 29, 2016
me1 wrote:
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
david_r wrote:

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
Evangelist
  • 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
david_r wrote:

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.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings