Question

Unique log file name containing username

  • 27 June 2018
  • 2 replies
  • 13 views

Userlevel 3
Badge +26

We currently have a single workbench stored in a central location being accessed and ran by various users, at various times. I would like to be able to incorporate the individuals system username into the log file name, as well as the date/time when they ran it. Is this possible?


2 replies

Userlevel 2
Badge +17

Hi @cartoscro,

This should be possible using Python scripted parameters. The location of the logfile is a workspace parameter that is normally left blank. However, if populated, it will override the default logfile location.

You can right-click on the Log File setting and create a non-Published User Parameter. This makes it settable by a Python scripted Parameter. We have a tutorial on using Scripted parameters available here.

The timestamp is simple, but getting the username in Python may be more complex. There is a good conversation on how to do it in Stack Overflow.

Userlevel 3
Badge +26

For future reference, I ended up using this along with @DaveAtSafe suggestion to get the username, workbench name, and date/time appended to the logfile name.

import getpass, time, os

n = getpass.getuser()
w = FME_MacroValues['FME_MF_NAME']
t = time.strftime('%Y_%m_%d_%H_%M_%S')

if w.endswith('.fmw'):
w = w[:-4]

path = n + '_' + w + '_' + t
return path

Easier than I thought it would be.

Reply