Symptoms

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.

Resolution

The procedure for writing to the logfile differs based on where you are running the script.

PythonCaller transformer
In a PythonCaller (or PythonCreator) transformer, messages are added to the logfile with the FMELogfile object, which is part of the pyfme package. You need to create a logger object (ie myLoggerObject = pyfme.FMELogfile()) and then you will need to send messages to the logger (ie myLoggerObject.log("Something happened that I want to log"))

Shutdown Script
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 that was cool, I should log it")
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 as print "wow that was cool, I should log it" to have it appear in the workbench window.

Examples of logging in a PythonCaller and in a shutdown script can be found in the attached workspace.