Python – Print Logs from FME Objects in CMD Efficiently

fme-formfmeobjectslogpython

I'm running a FME Workbench from my Python script and I struggle to print the log in the cmd.

When I run the FME Workbench (from FME without Python), I got this error in the FME translation log :

2022-04-20 10:15:57|   4.7|  0.2|ERROR |Bulk copy failed on table 'test_fme.SIG.ESP_NET_ApportVolontaire' using delimiter ':'. Error was 'ERROR:  null value in column "objectid_sde" violates not-null constraint
DETAIL:  Failing row contains (83858, null, 29019, 26/01/2022, GV, La poste st jacques_GV (ER), provisoire, GV142A1, null, null...'

I'd like this log to be printed in the cmd when I run the FME Workbench with Python. I got a loop for that :

for couche in ListeCouches :

        try :

            parameters = {}
            parameters['FEATURE_TYPES'] = couche 

            workspace.runWithParameters(workspace_path,parameters)

            print(couche)

    except Exception as ex:
        print(ex)

            continue

I've read stuffs with

logger = fmeobjects.FMELogFile()
logger.logMessageString("{}".format('Error'), fmeobjects.FME_ERROR)

but I don't understand what to do with.

Best Answer

I think the logger snippet you added at the end is for writing to the FME log file when you have python embedded in your FME Workspace. Whether that's part of a python startup or shutdown script, or a PythonCaller, etc. See the documentation.

If I understand correctly, you want to print the FME log file to the python console when you run your code to launch FME.

One way to do this is to read the log file after it has been written and print to the console.

Something like the following:

FMELog= open(theFMELogFilePath, 'r')
for line in FMELog.readlines():
    print line

Of course, this won't display the log immediately, it will print only when the workspace has completed.

Related Question