Question

FME 2020: Python print commands are not showing in the log file

  • 3 April 2020
  • 9 replies
  • 66 views

Badge +1

We have just upgraded to FME 2020.0.0.1 and are slowly testing our different workspaces.

We use the python print command to log different things into the FME log file and since we have upgraded to 2020 all these log statements has disappeared form the log file. Python compatibility is set to 3.7+.

Is that somehow a feature or a bug?


9 replies

Userlevel 4

I just tested with the exact same version and it works for me... Did you Ctrl-F the print statement in the log window to try and locate it?

Notice that the print statements appeared differently in earlier versions of FME with Python 2.7, they had a tendency to bunch up at the end of the log. They are now properly logged and timestamped in the order they occur.

Badge +1

I just tested with the exact same version and it works for me... Did you Ctrl-F the print statement in the log window to try and locate it?

Notice that the print statements appeared differently in earlier versions of FME with Python 2.7, they had a tendency to bunch up at the end of the log. They are now properly logged and timestamped in the order they occur.

Is there a difference between the contents of the log window and the log file? We execute FME desktop headless so we never see the log window.

 

 

I did put some very easy-to-find print statements but I couldn't find them. I know that previous versions of FME put all the print statements in the end, but I think it was FME 2019 that was able to put them correctly inside the logfile.
Userlevel 4

If you want to insert messages both into the FME log window and log file, in a way that is predictable in all situations (Desktop and Server), I would recommend against using print statements and rather use the fmeobjects API:

import fmeobjects
fmeobjects.FMELogFile().logMessageString('Hello World!', fmeobjects.FME_INFORM)

Also look at the API doc: https://docs.safe.com/fme/html/fmepython/api/fmeobjects/_log/fmeobjects.FMELogFile.logMessageString.html#fmeobjects.FMELogFile.logMessageString

Badge +1

If you want to insert messages both into the FME log window and log file, in a way that is predictable in all situations (Desktop and Server), I would recommend against using print statements and rather use the fmeobjects API:

import fmeobjects
fmeobjects.FMELogFile().logMessageString('Hello World!', fmeobjects.FME_INFORM)

Also look at the API doc: https://docs.safe.com/fme/html/fmepython/api/fmeobjects/_log/fmeobjects.FMELogFile.logMessageString.html#fmeobjects.FMELogFile.logMessageString

That's exactly what we would do if our python code was only for FME. But we have quite a bit of python code which we both execute using a PythonCaller and from outside FME (where we don't have access to fmeobjects).
Userlevel 4
That's exactly what we would do if our python code was only for FME. But we have quite a bit of python code which we both execute using a PythonCaller and from outside FME (where we don't have access to fmeobjects).

Ah, that makes sense. In that case you might also want to consider using the Python logging module whenever possible.

It might also be an idea to write some helper functions that output messages to FMELogFile or the logging module depending on what is available at runtime.

Userlevel 4

Is there a difference between the contents of the log window and the log file? We execute FME desktop headless so we never see the log window.

 

 

I did put some very easy-to-find print statements but I couldn't find them. I know that previous versions of FME put all the print statements in the end, but I think it was FME 2019 that was able to put them correctly inside the logfile.

Can you perhaps post a minimal workspace here that demonstrates the issue?

Badge +1

Can you perhaps post a minimal workspace here that demonstrates the issue?

I have just created a new workspace and added a print statement in the "Startup Python Script" script and it works just fine. I will investigate further to see if it has something to do with custom transformers or maybe because we have older workspaces which we now try to execute in 2020. Thank you for all your suggestions :)

Hi, I am having the exact same problem with FME 2021. We just upgraded from FME 2019. Used to using the print statement in the python caller but in FME 2021 no statements appear in the translation log, very annoying as I use these statements a lot when writing the python scripts.. Is there a solotion for this?

Userlevel 4

Hi, I am having the exact same problem with FME 2021. We just upgraded from FME 2019. Used to using the print statement in the python caller but in FME 2021 no statements appear in the translation log, very annoying as I use these statements a lot when writing the python scripts.. Is there a solotion for this?

I've already posted the "official" way of writing to the FME log above, see the code example using the logMessageString() method.

Reply