Code Snippet: logging fdmContext values

Object fdmContext is the dictionary FDMEE uses to store context information such as Location Name, Import Format Name, Process Id, etc. Most of the values stored in fdmContext are specific for the current process being executed. Others are global to all processes.

If you want to learn more about dictionaries in Python/Jython, please visit this tutorial.

Logging all fdmContext properties (loop sorted dictionary)

Not sure which are the values you can get from fdmContext at any event script?
Simply include this snippet into your event script and see results in the FDMEE process log.


'''
Snippet: Log content of fdmContext object
Author: Francisco Amores
Date: 11/11/2016
Blog: http://fishingwithfdmee.blogspot.com

Notes: This snippet can be pasted in any event script.
Content of fdmContext object will be logged in the
FDMEE process log (...\outbox\logs\)
Instructions: Set log level (global or application settings) to 5
Hints: Use this snippet to see different context values
at any workflow step.

FDMEE Version: 11.1.2.3 and later
----------------------------------------------------------------------
Change:
Author:
Date:
'''

# initialize
logLines = ""

# loop all fdmContext keys (sorted)
for key in sorted(fdmContext):
# get key value
value = fdmContext[key]
# build log line (property name: property value)
logLines += "%s: %s\n" % (key, value)

# write line to log (Debug)
if logLines:
fdmAPI.logDebug("Content of fdmContext: \n%s" % logLines)
else:
fdmAPI.logWarn("Nothing to log from fdmContext")

Logging all fdmContext properties (list comprehension)

First, make it working. Then, make it Jythonic. Try to simplify your code and make it more readable.
We can also use list comprehension to build lists dynamically:


'''
Snippet: Log content of fdmContext object
Author: Francisco Amores
Date: 11/11/2016
Blog: http://fishingwithfdmee.blogspot.com

Notes: This snippet can be pasted in any event script.
Content of fdmContext object will be logged in the
FDMEE process log (...\outbox\logs\)

This script uses list comprehension builder

Instructions: Set log level (global or application settings) to 5
Hints: Use this snippet to see different context values
at any workflow step.

FDMEE Version: 11.1.2.3 and later
----------------------------------------------------------------------
Change:
Author:
Date:
'''

# initialize
logLines = ""

# List comprehension
# Define list with pairs "Key: Value" from sorted fdmContext
list = ["%s: %s" % (key, fdmContext[key]) for key in sorted(fdmContext)]
# List is then joined with "\n" character (newline)
logLines = "\n".join(list)

# write line to log (Debug)
if logLines:
fdmAPI.logDebug("Content of fdmContext: \n%s" % logLines)
else:
fdmAPI.logWarn("Nothing to log from fdmContext")

Code snippets for FDMEE can be downloaded from GitHub.

0 Response to "Code Snippet: logging fdmContext values"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel