# Scripting Functions Using ScriptManager - Printing/Logging

**URL:** <https://forum.inductiveautomation.com/t/scripting-functions-using-scriptmanager-printing-logging/80980>\
**Category:** Module Development\
**Created:** [October 25, 2023, 6:17pm UTC](https://forum.inductiveautomation.com/t/scripting-functions-using-scriptmanager-printing-logging/80980 "2023-10-25T18:17:23Z")\
**Posts on this page:** 9\
**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:** [October 25, 2023, 6:17pm UTC](https://forum.inductiveautomation.com/t/scripting-functions-using-scriptmanager-printing-logging/80980/1 "2023-10-25T18:17:24Z")

</div>

I'm writing some scripting functions using the ScriptManager class. I'm using it to create a ScriptFunction class, based on a string of Python code.

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

From what I can tell, it appears to work, but for whatever reason, I'm not able to see any prints in the Script Console. Although they show up in the Designer's console just fine.

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

I'm assuming that technically, the function works, but it's jarring to not be able to see anything about in the script console. Why would this be the case? I would guess it's related to scoping, and maybe with the Designer and Gateway Hook implementations.

And actually, for another function where a very large dataset is being returned, instead of the usual \<PyDataset: 45120 rows\> output, it's attempting to print the full dataset with every piece of data listed. Which just kills the designer.

What should I be looking out for, to get the logging and printing to behave like regular native Ignition functions, or functions written in the scripting library?

---

<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:** [October 25, 2023, 6:55pm UTC](https://forum.inductiveautomation.com/t/scripting-functions-using-scriptmanager-printing-logging/80980/2 "2023-10-25T18:55:55Z")

</div>

This is expected behavior - you'd get the exact same output if you had written that code yourself in the script console:

> [@Event Configuration Print Out to debug](https://forum.inductiveautomation.com/t/event-configuration-print-out-to-debug/60091/5):
>
> It’s complicated slight_smile Starting from most local to least… In the script console, print will log directly to the output buffer on the right hand side. system.util.getLogger() will log to the named ‘Output Console’ Designer window. Bonus: A script invoked from here using system.util.invokeAsync will print to the regular output console, not the buffer on the right hand side. Anywhere else in the designer (except Perspective), print and system.util.getLogger will log to the ‘Out…

The script console is a bit of a one-off unicorn; it manually "wraps" the `stdout` and `stderr` buffers for code executing inside itself. Logging should be considered a "side channel" for information capture - if you want something to be visible to the caller, your options are to return it directly or write it to `stdout` (which itself has caveats for gateway scope). No free lunch, unfortunately.

---

<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:** [October 25, 2023, 7:22pm UTC](https://forum.inductiveautomation.com/t/scripting-functions-using-scriptmanager-printing-logging/80980/3 "2023-10-25T19:22:59Z")

</div>

Thanks as always Paul 🙂

A followup question though, nowhere in the function definition in the string, am I putting any log statements. So I might be missing something somewhere, but seems like the return value is always being printed in the 'Output Console'. This is fine, except for when a function is returning a potentially very large dataset. Here is an example where it's trying to print out the whole dataset, and freezing up.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/f/6f1228a4d4bbb9e4d2024447b54a805c52f172b4.jpeg)

Is there anyway I can control what gets printed out in this case?

---

<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:** [October 27, 2023, 5:49pm UTC](https://forum.inductiveautomation.com/t/scripting-functions-using-scriptmanager-printing-logging/80980/4 "2023-10-27T17:49:10Z")

</div>

So I've been trying to wrap my head around it a bit more. Running code in the script console, is always ran in the designer scope? So when I'm calling a function written in the scripting library, or even defined in the script console itself; what's the difference between that, and running a function written in a third party module?

---

<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:** [October 27, 2023, 5:55pm UTC](https://forum.inductiveautomation.com/t/scripting-functions-using-scriptmanager-printing-logging/80980/5 "2023-10-27T17:55:47Z")

</div>

> [@Jason\_Zhou](#):
>
> Running code in the script console, is always ran in the designer scope?

Yes.

> [@Jason\_Zhou](#):
>
> what's the difference between that, and running a function written in a third party module?

Third party modules must install jars and hook classes for each process scope they wish to support: gateway, client, and designer. A third party module may register java functions under python names in `system.*`, and run arbitrary jython code. In designer or client scopes, the jython code run from within the module will use that same scope, unconditionally. In gateway scope, the arbitrary code will run in the non-perspective project scope for the script manager selected. Typically, this would be non-project scope, with gateway scripting project resources, if any, available.

Third party modules can also install remote procedure call support, so that client and designer scopes can call out to gateway scope.

---

<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:** [October 27, 2023, 6:11pm UTC](https://forum.inductiveautomation.com/t/scripting-functions-using-scriptmanager-printing-logging/80980/6 "2023-10-27T18:11:41Z")

</div>

I've set up the DesignerHook (correctly I hope), and the function technically works just fine. The only difference in behavior I'm seeing so far, is where it decides to print things.

But you also mentioned installing jars, could you elaborate on that a bit more? Perhaps I'm missing something there.

---

<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:** [October 27, 2023, 6:13pm UTC](https://forum.inductiveautomation.com/t/scripting-functions-using-scriptmanager-printing-logging/80980/7 "2023-10-27T18:13:59Z")

</div>

Jars are inside your module file. Your module specifies in module.xml which jars get installed in which scopes, and which scopes have hook classes to invoke.

---

<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:** [October 27, 2023, 6:41pm UTC](https://forum.inductiveautomation.com/t/scripting-functions-using-scriptmanager-printing-logging/80980/8 "2023-10-27T18:41:34Z")

</div>

Got it, it seems like those are set up correctly too.

I did some experimenting just now, and it seems like it's something about the ScriptManager. I created a function that just runs pure Java, and it prints in the output buffer just fine. Also of note, it didn't print in the Output Console in the designer.

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

So back to the screenshot in the original post, it shows how I'm defining a function. I'd like to understand more about what's going on with the ScriptManager's compileFunction(), and ScriptFunction's .invoke(). What are the differences between that implementation, vs. just implementing it directly in Java code? I'm thinking there's some differences in scopes.

---

<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:** [October 27, 2023, 8:05pm UTC](https://forum.inductiveautomation.com/t/scripting-functions-using-scriptmanager-printing-logging/80980/9 "2023-10-27T20:05:56Z")

</div>

You are blazing a new trail, I think. I would not expect a script manager obtained in your module from the module context to be the same environment as for the **caller** of your registered script function. It might be in Vision Client scope, but I wouldn't bet on it.

And loggers don't ever output to the designer script console. And module code that prints to System.stdout or System.stderr should expect their output to **only** go to the debug console/wrapper log.

Pssst! What do you really need to do? You shouldn't be running predefined jython within your java module, I wouldn't think.
