Skip to main content
Solved

FME 2018.1+ Python Shutdown Script Logging

  • February 12, 2019
  • 13 replies
  • 107 views

tino
Supporter
Forum|alt.badge.img+23
  • Supporter
  • 30 replies

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?

Best answer by debbiatsafe

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

13 replies

tino
Supporter
Forum|alt.badge.img+23
  • Author
  • Supporter
  • 30 replies
  • February 12, 2019

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


david_r
Celebrity
  • 8392 replies
  • February 12, 2019

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.


debbiatsafe
Safer
Forum|alt.badge.img+21
  • Safer
  • 648 replies
  • February 13, 2019

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.


debbiatsafe
Safer
Forum|alt.badge.img+21
  • Safer
  • 648 replies
  • Best Answer
  • February 25, 2019

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.

tino
Supporter
Forum|alt.badge.img+23
  • Author
  • Supporter
  • 30 replies
  • February 26, 2019

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!


Forum|alt.badge.img
  • 7 replies
  • October 22, 2019

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?


david_r
Celebrity
  • 8392 replies
  • October 22, 2019

Does that only work for python 3?

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


stezi
Contributor
Forum|alt.badge.img+6
  • Contributor
  • 21 replies
  • March 25, 2020

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?


david_r
Celebrity
  • 8392 replies
  • March 25, 2020

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.


stezi
Contributor
Forum|alt.badge.img+6
  • Contributor
  • 21 replies
  • March 25, 2020

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?


david_r
Celebrity
  • 8392 replies
  • March 25, 2020

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.

 


stezi
Contributor
Forum|alt.badge.img+6
  • Contributor
  • 21 replies
  • March 25, 2020

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)?


david_r
Celebrity
  • 8392 replies
  • March 25, 2020

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!