# system.util.getLogger problem

**URL:** <https://forum.inductiveautomation.com/t/system-util-getlogger-problem/51510>\
**Category:** Ignition\
**Created:** [September 30, 2021, 6:37pm UTC](https://forum.inductiveautomation.com/t/system-util-getlogger-problem/51510 "2021-09-30T18:37:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![wpmccormick](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wpmccormick/32/13940_2.png) [@wpmccormick](https://forum.inductiveautomation.com/u/wpmccormick)\
**Post date:** [September 30, 2021, 6:37pm UTC](https://forum.inductiveautomation.com/t/system-util-getlogger-problem/51510/1 "2021-09-30T18:37:45Z")

</div>

I’m trying to get system/gateway logging working on a system. I have a very simple Project Library script call TestLogger:

```auto
import system.util

def runTest():
	logger = system.util.getLogger('test')
	
	logger.info('testing')

```

And on a button click actionPerformed I run:

```auto
TestLogger.runTest()

```

So I see my _testing_ message in the Help-\>Diagnostics-\>LogViewer, but I expect to also see it in the web interface Status-\> Logs, where I have Scripting.ScriptManager.Project[TestLogger] set to Trace in Log Configuration.

I forget how this works exactly, but should I also be seeing a logger named _test_?

What am I missing here?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 30, 2021, 6:54pm UTC](https://forum.inductiveautomation.com/t/system-util-getlogger-problem/51510/2 "2021-09-30T18:54:27Z")

</div>

> [@wpmccormick](#):
>
> should I also be seeing a logger named _test_ ?

Not in this instance because you're calling it from a client scope. If the gateway calls it, it would show up in the gateway's log.

---

<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:** [September 30, 2021, 6:54pm UTC](https://forum.inductiveautomation.com/t/system-util-getlogger-problem/51510/3 "2021-09-30T18:54:47Z")

</div>

Designer and Vision Clients log locally. You will not see their output in the gateway.

---

<div class="post-metadata">

**Author:** ![wpmccormick](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wpmccormick/32/13940_2.png) [@wpmccormick](https://forum.inductiveautomation.com/u/wpmccormick)\
**Post date:** [September 30, 2021, 7:04pm UTC](https://forum.inductiveautomation.com/t/system-util-getlogger-problem/51510/4 "2021-09-30T19:04:14Z")

</div>

I could have sworn I’ve done this before.

I have a Vision Client that runs some extrememly convoluted shared gateway script. I need to start untangling it, and I thought logging some debug level messages to capture certain values after certain user actions would be extremely useful.

Is there no way to get a message logged to the gateway? I can’t burdon the user with taking over their workstation to look at logger messages.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 30, 2021, 7:08pm UTC](https://forum.inductiveautomation.com/t/system-util-getlogger-problem/51510/5 "2021-09-30T19:08:04Z")

</div>

I’ve made the same mistake.

You say the user is running some convoluted gateway script - is it running it on the gateway via a message handler (or gateway tag change)? If so - those logs would in fact appear in the logs on your gateway webpage.

If you need the logged to the gateway, have the client send a message to a gateway message handler to run whatever you need on the gateway, and then whatever is logged in that context will be on your gateway logs.

---

<div class="post-metadata">

**Author:** ![wpmccormick](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wpmccormick/32/13940_2.png) [@wpmccormick](https://forum.inductiveautomation.com/u/wpmccormick)\
**Post date:** [September 30, 2021, 7:11pm UTC](https://forum.inductiveautomation.com/t/system-util-getlogger-problem/51510/6 "2021-09-30T19:11:39Z")

</div>

> [@bkarabinchak.psi](#):
>
> send a message to a gateway message handler

Not sure I've done this before. Please elaborate.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 30, 2021, 7:16pm UTC](https://forum.inductiveautomation.com/t/system-util-getlogger-problem/51510/7 "2021-09-30T19:16:16Z")

</div>

Under Gateway Event Scripts you can set up a Message Handler like this -

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

and then from your client you can send it a payload (data pertinent to whatever you are running, if needed) via [system.util.sendMessage - Ignition User Manual 8.0 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC80/system.util.sendMessage) . Then, whatever happens inside that myMessageHanlder script `def handleMessage(payload):` - that is running on the gateway, not the client, and so any logging will go to the gateway logs.

You can go the reverse way as well, so when the gateway script finishes, you can send some result code to the client by making a Client Message Handler in a similar fashion. To do this, I’d suggest making [system.util.getClientId - Ignition User Manual 8.0 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC80/system.util.getClientId) as part of your payload so that when you are done inside your gateway script, you know exactly how to target which specific client will get the result message.

---

<div class="post-metadata">

**Author:** ![wpmccormick](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wpmccormick/32/13940_2.png) [@wpmccormick](https://forum.inductiveautomation.com/u/wpmccormick)\
**Post date:** [September 30, 2021, 7:49pm UTC](https://forum.inductiveautomation.com/t/system-util-getlogger-problem/51510/8 "2021-09-30T19:49:09Z")

</div>

Cool. So just to wrap this up and put a bow on for the next sorry sod …

In my SharedProject Gateway Event Scripts, I added a logMessageHandler:

```auto
def handleMessage(payload):
	"""
	This message handler will be called each time a message of this
	type is received.

	Arguments:
		payload: A dictionary that holds the objects passed to this
		         message handler. Retrieve them with a subscript, e.g.
		         myObject = payload['argumentName']
	"""
	import system.util
	
	logger = system.util.getLogger(payload['logger'])
	
	level = payload['level'].lower()
	message = payload['message']
	
	if level == 'info':
		logger.info(message)
	elif level == 'trace':
		logger.trace(message)
	elif level == 'debug':
		logger.debug(message)
	elif level == 'warn':
		logger.warn(message)
	elif level == 'error':
		logger.error(message)
	elif level == 'fatal':
		logger.fatal(message)
	else:
		logger.warn('Unknown level in logMessageHandler')

```

Then, in some Project Library Script:

```auto
def runTest():
	system.util.sendMessage('TestLogger','logMessageHandler',{'logger':'test','level':'info','message':'testing log message handler'})

```

Note that my TestLogger project inherits from my GatewayScripts project, so it needs to be the one referenced.

Now I see something useful. Thanks!

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [October 1, 2021, 5:26pm UTC](https://forum.inductiveautomation.com/t/system-util-getlogger-problem/51510/9 "2021-10-01T17:26:46Z")

</div>

@pturmel showed a simpler way to handle the levels a while back if you want to shorten your code:

> [@\[SOLVED\] Logging client scoped events to gateway](https://forum.inductiveautomation.com/t/solved-logging-client-scoped-events-to-gateway/37330/4):
>
> Psst! Try this: logger = system.util.getLogger(payload['loggerName']) m = getattr(logger, payload['level']) m(payload['message'])
