# Function Exception Logging: Capturing Source

**URL:** <https://forum.inductiveautomation.com/t/function-exception-logging-capturing-source/93156>\
**Category:** Module Development\
**Tags:** perspective\
**Created:** [July 12, 2024, 4:51pm UTC](https://forum.inductiveautomation.com/t/function-exception-logging-capturing-source/93156 "2024-07-12T16:51:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Zhou](https://avatars.discourse-cdn.com/v4/letter/j/6bbea6/32.png) [@Jason\_Zhou](https://forum.inductiveautomation.com/u/Jason_Zhou)\
**Post date:** [July 12, 2024, 4:51pm UTC](https://forum.inductiveautomation.com/t/function-exception-logging-capturing-source/93156/1 "2024-07-12T16:51:00Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/d/9d871996a68dc70508a48c2f66218d63f4fdb6a5.png)

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?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 12, 2024, 5:05pm UTC](https://forum.inductiveautomation.com/t/function-exception-logging-capturing-source/93156/2 "2024-07-12T17:05:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jason\_Zhou](https://avatars.discourse-cdn.com/v4/letter/j/6bbea6/32.png) [@Jason\_Zhou](https://forum.inductiveautomation.com/u/Jason_Zhou)\
**Post date:** [July 12, 2024, 5:09pm UTC](https://forum.inductiveautomation.com/t/function-exception-logging-capturing-source/93156/3 "2024-07-12T17:09:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 12, 2024, 5:13pm UTC](https://forum.inductiveautomation.com/t/function-exception-logging-capturing-source/93156/4 "2024-07-12T17:13:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jason\_Zhou](https://avatars.discourse-cdn.com/v4/letter/j/6bbea6/32.png) [@Jason\_Zhou](https://forum.inductiveautomation.com/u/Jason_Zhou)\
**Post date:** [July 12, 2024, 5:24pm UTC](https://forum.inductiveautomation.com/t/function-exception-logging-capturing-source/93156/5 "2024-07-12T17:24:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 12, 2024, 5:37pm UTC](https://forum.inductiveautomation.com/t/function-exception-logging-capturing-source/93156/6 "2024-07-12T17:37:57Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Jason\_Zhou](https://avatars.discourse-cdn.com/v4/letter/j/6bbea6/32.png) [@Jason\_Zhou](https://forum.inductiveautomation.com/u/Jason_Zhou)\
**Post date:** [July 12, 2024, 5:43pm UTC](https://forum.inductiveautomation.com/t/function-exception-logging-capturing-source/93156/7 "2024-07-12T17:43:57Z")

</div>

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