span8
span4
span8
span4
Writing messages to the FME logfile in a Python script can be tricky. If you use a simple print "message", the line will be printed in the log window, but NOT saved in the logfile.
Please note: this article has been updated for FME 2012 and beyond where we have moved to fmeobjects rather than pyfme for our Python FME Objects API
The procedure for writing to the logfile differs based on where you are running the script.
In a PythonCaller (or PythonCreator) transformer, messages are added to the logfile with the FMELogFile object, which is part of the fmeobjects. You need to create a logger object:
logger = fmeobjects.FMELogFile()
and then you will need to send messages to the logger:
logger.logMessageString("Hello I am Logging Now")
Logging in a shutdown script is a bit trickier. At this point in the lifecycle of the workspace, the workspace has been disconnected from the fme process, so the FMELogfile object no longer works. Instead you will need to get the location of the logfile on disk with FME_LogFileName parameter and use Python's built-in file functionality to add lines to the logfile, for example:
logger = open(FME_LogFileName,'a') logger.write("wow - this message will actually be written to log file") logger.close()
Note: Lines logged in this way will NOT appear in the log window in workbench, but will be appended to the end of the logfile on disk. If you want something to appear in both places you will need to write it to the logfile, as well like this:
打印“哇,这个消息很快就会回来的l only go to log window"
Examples of logging in a PythonCaller and in a shutdown script can be found in the attached workspace.
Note: If you are running Python scripts on FME Server, any error messages produced by the interpreter will be written out to the Process Monitor Engine log file rather than the Workspace log. This file can be found in
For a complete overview of using Python with FME please see the articlePython and FME Basics
Using a Python Startup/Shutdown Script or PythonCaller to Perform Geoprocessing with Arcpy
Create Spatial Index after loading to ArcSDE - using Load only mode
Transfer Workspace File Output Using SFTP (FME Server 2015 and below)
Example Workflow using FME, Python and Oracle
Setting up a workspace to deploy in production, staging and local
Startup and Shutdown TCL Script Examples
Published Parameter use within a Startup or Shutdown Script
Extracting a schema subset for dynamic schemas
Pass a List of Tables or Layers to an FME Reader using Python Scripted Parameters
Adding Fields to an Existing Feature Class with FME and ArcPy
© 2019 Safe Software Inc |Legal