# Troubleshooting tag event script suggestions?

**URL:** <https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560>\
**Category:** Ignition\
**Created:** [July 15, 2019, 6:50pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560 "2019-07-15T18:50:20Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![christopher.berg](https://avatars.discourse-cdn.com/v4/letter/c/67e7ee/32.png) [@christopher.berg](https://forum.inductiveautomation.com/u/christopher.berg)\
**Post date:** [July 15, 2019, 6:50pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560/1 "2019-07-15T18:50:20Z")

</div>

I have a situation that I need some assistance with. I’m not much of a coder and I’ve been tasked with troubleshooting a project someone else wrote. We’ve got a UDT for each workstation. On that UDT are tags for some call buttons, Button 1, 2, 3, etc. On those call button tags are tag event scripts triggered by a value change that log, in an SQL table, what button was pressed on what station, at what time, and how long it it was active.

Button 3 is being logged properly at station 1 but not 2 and I’m trying to figure out why.

When Button 3 is pressed at station 1, all the desired information is logged. When Button 3 is pressed at station 2, nothing gets logged although it does for the other two buttons. I can see that the associated tag values _are_ changing so the logging should be triggered.

As it stands right now, there’s no way to see what happens when the script is triggered _that I’m aware of_. If I’m not seeing it, please point me in the right direction. How can I generate a log so I can see if there’s an error occurring when the tag event script executes? The training videos mention wrapper logs or something similar that you can create but it went over my head.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 15, 2019, 7:36pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560/2 "2019-07-15T19:36:00Z")

</div>

If the tag diagnostics on the tags are not showing any error, then, your best bet is to implement a logger with a try…except structure.

Something like:

```auto
import java.lang.Exception
logger = system.util.getLogger("yourLoggerName")

try:
     #script to attempt
except: java.lang.Exception, e:
     logger.warn("An error occurred" , e)
except Exception, e:
     logger.warnf("An error occurred: %s",e)

```

@pturmel has a PythonAsJavaException class in his [later.py](https://www.automation-pros.com/ignition/later.py) which will allow for more detail in the case of python exceptions

---

<div class="post-metadata">

**Author:** ![christopher.berg](https://avatars.discourse-cdn.com/v4/letter/c/67e7ee/32.png) [@christopher.berg](https://forum.inductiveautomation.com/u/christopher.berg)\
**Post date:** [July 18, 2019, 1:21pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560/3 "2019-07-18T13:21:27Z")

</div>

Thanks for your reply. I got back to this today. I added your code around the code I’m trying to troubleshoot and tested the buttons. I’m not seeing anything in the logs though. Can I assume that an exception in these circumstances would be something like, say, a DB query looking for a column that doesn’t exist, where SQL would generally throw an error?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 18, 2019, 4:25pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560/4 "2019-07-18T16:25:45Z")

</div>

If SQL throws and error, it would be caught and printed to the log. If you are not seeing any errors in the log, this means 1 of 2 things.

1.) The code is not being executed. You have already stated that the tag values are changing, and we can be fairly sure that Ignition is raising the value change event. That leaves only the possibility that some conditional code is causing the script which would log any errors to not be executed. Probably a safe bet this isn't the case.

2.) The code is not throwing any errors. This seems to be the most logical conclusion from what you have posted. This would mean that values in the code are not what you expect them to be. I would recommend using the logger more extensively, much like you would use the print statement for debugging purposes in the console.

The logger has multiple functions for logging various types of information at various levels of severity.

From the manual:

> - Logger.fatal(String) - Logs a message with level fatal.
> - Logger.fatalf(String, Args...) - Logs a formatted message with level fatal,  
> using Java's Formatter syntax.
> - Logger.error(String) - Logs a message with level error.
> - Logger.errorf(String, Args...) - Logs a formatted message with level error, using Java's Formatter syntax.
> - Logger.warn(String) - Logs a message with level warn.
> - Logger.warnf(String, Args...) - Logs a formatted message with level warn, using Java's Formatter syntax.
> - Logger.info(String) - Logs a message with level info.
> - Logger.infof(String, Args...) - Logs a formatted message with level info, using Java's Formatter syntax.
> - Logger.debug(String) - Logs a message with level debug.
> - Logger.debugf(String, Args...) - Logs a formatted message with level debug, using Java's Formatter syntax.
> - Logger.trace(String) - Logs a message with level trace.
> - Logger.tracef(String, Args...) - Logs a formatted message with level trace, using Java's Formatter syntax.
> - Logger.isTraceEnabled() - Returns True if the current log level is at least trace.
> - Logger.isDebugEnabled() - Returns True if the current log level is at least debug.
> - Logger.isInfoEnabled() - Returns True if the current log level is at least info.

---

<div class="post-metadata">

**Author:** ![christopher.berg](https://avatars.discourse-cdn.com/v4/letter/c/67e7ee/32.png) [@christopher.berg](https://forum.inductiveautomation.com/u/christopher.berg)\
**Post date:** [July 22, 2019, 11:53am UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560/5 "2019-07-22T11:53:35Z")

</div>

I think the issue is the latter you described. It’s executing and the query is just coming up empty. Since the query is attached to a UDT and the same UDT is used across several stations, why we’re getting the results we want on several other stations but not this one is confusing. I’m trying to figure out what’s different about the problem station compared to the others. I appreciate your responses.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 5, 2024, 3:24pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560/6 "2024-04-05T15:24:34Z")

</div>

3 posts were split to a new topic: [Jython exception syntax error](https://forum.inductiveautomation.com/t/jython-exception-syntax-error/88434)

---

<div class="post-metadata">

**Author:** ![Zach\_Larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zach_larson/32/54388_2.png) [@Zach\_Larson](https://forum.inductiveautomation.com/u/Zach_Larson)\
**Post date:** [April 5, 2024, 3:31pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560/7 "2024-04-05T15:31:20Z")

</div>

I tried to use the code in post 2, and I got errors.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 5, 2024, 3:38pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560/8 "2024-04-05T15:38:04Z")

</div>

> [@Zach\_Larson](#):
>
> got errors.

That's because that code has the same extra colon I mentioned elsewhere.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [April 5, 2024, 3:39pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560/9 "2024-04-05T15:39:21Z")

</div>

In addition to what @pturmel has mentioned about the extra ':', you also have not used the full script neglecting to import the Java type, and not defining the logger.

---

<div class="post-metadata">

**Author:** ![Zach\_Larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zach_larson/32/54388_2.png) [@Zach\_Larson](https://forum.inductiveautomation.com/u/Zach_Larson)\
**Post date:** [April 5, 2024, 3:42pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560/10 "2024-04-05T15:42:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 5, 2024, 3:43pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560/11 "2024-04-05T15:43:54Z")

</div>

See my mention of `PythonAsJavaException` in the new topic.

---

<div class="post-metadata">

**Author:** ![Zach\_Larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zach_larson/32/54388_2.png) [@Zach\_Larson](https://forum.inductiveautomation.com/u/Zach_Larson)\
**Post date:** [April 5, 2024, 3:45pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560/12 "2024-04-05T15:45:33Z")

</div>

Every time I attempt to use an example try except with a logger, it throws errors, and I get instructions that I don't understand.

I tried using chatGPT and it starts using a different syntax that throws different errors.

Is there a spot that explains it well?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 5, 2024, 3:52pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560/13 "2024-04-05T15:52:35Z")

</div>

1. You revived an ancient topic,

2. You tried to use **part of** the code,

3. For a _ **different purpose** _ (catching division by zero instead of a database error),

4. When I split to a new topic, you continued here. Go back and unbreak the split.

I'm done **here**.

---

<div class="post-metadata">

**Author:** ![Zach\_Larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zach_larson/32/54388_2.png) [@Zach\_Larson](https://forum.inductiveautomation.com/u/Zach_Larson)\
**Post date:** [April 5, 2024, 3:55pm UTC](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560/14 "2024-04-05T15:55:00Z")

</div>

I wanted to be able to find the thread.  
I didn't know a better test error.
