How to get the debug print result from a gateway scheduled event

I have a gateway script (a scheduled event). it runs well every day. there is a print function in this script. How can I get the print result?

I know I can call this gateway script in script console to get the print result. But I can 't do this as this script will changing database. Is there any other method to get the print result? Thanks!

Printing in gateway scope goes only to the wrapper log text files. Instead, you should use a logger from system.util.getLogger(), and use the INFO level methods.

1 Like

So I should change the print function to system.util.getLogger() in this gateway script. To create an INFO level log instead, then I can go to the Gateway _ Status _ Diagnostics _ Logs to find this log and then review the info. Am I right?

Yes. But for efficiency, get one logger instance at the top level of your script module, and use that instance for all your logging.

Good suggestion ! I will only create one log instance, and use it for my logging.
image
Thank you so much !

If that is a snip from a project library script (and it should be), then line 480 should be moved to near the top of the script, un-indented (outside any function). That is most efficient--one logger instance for the entire script, established on project startup when the script library is initialized.

Yes, it is a snip from my project library script inside a function (sendEmail). And this project script is overall a class (named Email). refer to below for outline of this class.

For my case, the line 480 can move to the outside of the class, or inside the class (above init() function), I think both are OK, but inside class is better. Am I right?

image

No, the logger instance setup should be outside of any class or function. If you want multiple different loggers in the same library script, make them all outside any class or function.

1 Like

Thanks for the advice. I have successfully get the log in the gateway logs.
But the string is long, how can I download it to review all details?

If you want the logged string in non-html form, you will need to either download the SQLite logs file and use an external SQLite tool, or access the wrapper.log file itself via the gateway OS.

FWIW, I generally open a remote terminal on the development gateway and use

tail --follow /path/to/install/logs/wrapper.log

while working with gateway and Perspective scripts.

1 Like

I can just use designer launcher, can not operate in gateway os. Alternatively, I made a copy of this class and made some modification, then call this new class in designer script console, successfuly got the all Email body html strings. I have found bugs in the html content and have ideas to solve them.

I think the logger is also a good tool when need get some info from gateway script.

Thank you for your kind help.

There is another good method for me. I can use system.tag.writeBlocking() function to write the string content into a memory tag, Then I can read from this tag to review details.

Haha! This is quite simple and useful for me ! :smiley:

You will be needlessly blocking all of your scripts potentially multiple times per call. Don’t do this.

On top of that, you won’t have historical record of your messages, unless you were to use a dataset tag, or multiple tags. Both of which come with potentially system crushing side effects.

Just use the method Phil suggested, really.

This gateway script runs 3 times per day (every 8hrs) and I just need this message for dubug purpose, no need historical data.
After confirm eveything goes well. I will remove it.

Thanks for your notice about the potential risk! :handshake:

I have followed the examples here, but do not see any print results in the wrapper.log text file. The script below is in a gateway event script timer based every 5 seconds.

print 'can you see me'
Logger = system.util.getLogger("myLogger")
Logger.info("Hello")

I expect that I am not looking in the correct location or method to see the print statement.

The wrapper log is a text file in the Ignition install folder, typically under a logs/ subfolder.

Don't use print.

I am looking here:C:\Program Files\Inductive Automation\Ignition\logs.
At file:wrapper.log
opening it with notepad, and can't find any result of my logger posts.
PS knon the print part does not work. I am counting on the logger part to work.

Here are the last few records from the file timestamped recently.
INFO | jvm 1 | 2024/12/13 15:17:08 | I [P.InternalDatabase ] [20:17:08]: Created auto-backup of internal database "config.idb" in 4 seconds
INFO | jvm 1 | 2024/12/13 15:31:08 | I [P.InternalDatabase ] [20:31:08]: Creating auto-backup of internal database "config.idb"...
INFO | jvm 1 | 2024/12/13 15:31:12 | I [P.InternalDatabase ] [20:31:12]: Created auto-backup of internal database "config.idb" in 3 seconds
INFO | jvm 1 | 2024/12/13 15:45:28 | I [s.ProjectRunner ] [20:45:28]: Setting SQL Bridge project enabled state to 'DISABLED' project-name=TestProject, module-name=SQL Bridge
INFO | jvm 1 | 2024/12/13 15:51:14 | I [g.LicenseManager ] [20:51:13]: Trial time reset. Time remaining = 7200. route-group=status, route-path=/trial
INFO | jvm 1 | 2024/12/13 15:51:14 | I [s.ProjectRunner ] [20:51:13]: Setting SQL Bridge project enabled state to 'ENABLED' project-name=TestProject, module-name=SQL Bridge

Edit your event script, with a trivial change, like a blank line at the top. Then save while monitoring your logs. If there's a syntax error or other error, it will only show up once.

I changed the script, saved the data, refreshed from the gateway and see no new records in the .log file. timestamp on the log file is still 3:51.