Function Exception Logging: Capturing Source

I'm writing scripting functions in Java, and if one of the functions were to be run from for example a perspective component script, or a tag script, I want to be able to capture that.

For example:

What I want here is for the magnifying glass icon to show up, along with the on-hover Log Properties, showing the project-name and view, where the function was called.

I'm using the org.slf4j.Logger to log exceptions. Is there anything I can do to also capture the source of whatever runs one of the scripting functions?

If your function is called from inside an existing Ignition scripting context, these mapped diagnostic context (MDC) keys will be automatically present and show up on your logged messages. Unless you're jumping thread boundaries in your scripting function execution.

Ahhh, unfortunately that's exactly what's going on. Thanks for the info.

You should probably be able to enumerate or copy the MDC from the thread where your script is invoked and pass it into your new thread.

1 Like

I'll try my hand and let you know how that goes, thanks for the pointer.

Probably:
In one thread:
org.slf4j.MDC.getCopyOfContextMap()

In the other thread:
org.slf4j.MDC.setContextMap(map)

1 Like

Yep that's what I ended up doing and it worked! Thanks a lot Paul.