Solved

FME 2018.1+ Python Shutdown Script Logging

  • 12 February 2019
  • 13 replies
  • 19 views

Badge +7

For years I have been using a small helper function to log in both FME Desktop Log Window and Logfile (and FME Server):

def myLogger(string):
    print(string)
    with open(fme.logFileName,"a") as f:
        f.write("{}\n".format(string))

With this, my log messages were written to the Logfile and when executed in FME Desktop Workbench also visible in the log window.

Now, FME 2018.1 and newer redirect stdout to info logging and stderr to warn logging in the FME session.

But in the Shutdown Script the FME Session has already been terminated.

Is there any way to put info into the FME Desktop Log Window from a Python Shutdown Script?

icon

Best answer by debbiatsafe 25 February 2019, 22:43

View original

13 replies

Badge +7

Just noticed: With Python 2.x it does still work, but not with 3.x.

Userlevel 4

Just noticed: With Python 2.x it does still work, but not with 3.x.

For what it's worth, I can confirm the exact same behavior on my end.

Userlevel 3
Badge +17

Hi @tino

Thank you for letting us know about this issue.

I've opened a bug report so our developers can investigate this issue. I will update this post once it has been resolved or if there are updates.

Userlevel 3
Badge +17

Hi @tino

I'm pleased to announce this issue has been fixed in the latest 2019.0 betas (build 19210+) and the next release of 2018 (build 18589+ --not currently available). You can find the latest installers here.

print() will now output to the translation log window. Thank you for your patience as we work through this issue.
Badge +7

Hi @tino

I'm pleased to announce this issue has been fixed in the latest 2019.0 betas (build 19210+) and the next release of 2018 (build 18589+ --not currently available). You can find the latest installers here.

print() will now output to the translation log window. Thank you for your patience as we work through this issue.

Yes, the latest 2019 beta does show the print output in the log window!

Very nice, thanks a lot!

Badge

Hi @tino

I'm pleased to announce this issue has been fixed in the latest 2019.0 betas (build 19210+) and the next release of 2018 (build 18589+ --not currently available). You can find the latest installers here.

print() will now output to the translation log window. Thank you for your patience as we work through this issue.

Does that only work for python 3?

Userlevel 4

Does that only work for python 3?

Both Python 2 and 3 should work identically in regards to print statements.

Badge +1

Hi @tino

I'm pleased to announce this issue has been fixed in the latest 2019.0 betas (build 19210+) and the next release of 2018 (build 18589+ --not currently available). You can find the latest installers here.

print() will now output to the translation log window. Thank you for your patience as we work through this issue.

I am still facing this issue with FME Server 2019.2.3.1Build 19823 - win64. Can you reproduce it?

Userlevel 4

I am still facing this issue with FME Server 2019.2.3.1Build 19823 - win64. Can you reproduce it?

The FME Desktop log window does not equal the FME Server job log, unfortunately. Any print statements in the workspace will therefore not appear in the job log, but in the system fmeprocessmonitorengine.log file.

Badge +1

The FME Desktop log window does not equal the FME Server job log, unfortunately. Any print statements in the workspace will therefore not appear in the job log, but in the system fmeprocessmonitorengine.log file.

Is it possible to create these job log messages with another command? Perhaps by using the FME python lib?

Userlevel 4

Is it possible to create these job log messages with another command? Perhaps by using the FME python lib?

Indeed, you can use Python to append messages to the job log. 

This is a small helper function that I often use in shutdown scripts:

import fme

def logFME(message):
    with open(fme.logFileName, 'a') as fmelog:
        fmelog.write(message.strip('\r\n') + '\n')
        fmelog.flush()

For everything that occurs inside PythonCreators or PythonCallers, you should use the FMELogFile object in stead, e.g.

from fmeobjects import FMELogFile, FME_INFORM

FMELogFile().logMessageString('My message', FME_INFORM)

You can consult the fmeobjects API doc for more information on this.

 

Badge +1

Indeed, you can use Python to append messages to the job log. 

This is a small helper function that I often use in shutdown scripts:

import fme

def logFME(message):
    with open(fme.logFileName, 'a') as fmelog:
        fmelog.write(message.strip('\r\n') + '\n')
        fmelog.flush()

For everything that occurs inside PythonCreators or PythonCallers, you should use the FMELogFile object in stead, e.g.

from fmeobjects import FMELogFile, FME_INFORM

FMELogFile().logMessageString('My message', FME_INFORM)

You can consult the fmeobjects API doc for more information on this.

 

thx!! It also possible to abort the translation with an error in the shutdown script (like sys.exit)?

Userlevel 4

thx!! It also possible to abort the translation with an error in the shutdown script (like sys.exit)?

I've never tried, but in principle the shutdown script doesn't execute before FME has decided whether the translation was successful or not, so it might not be possible. But by all means, try sys.exit() and see!

Reply