system.util.getLogger problem

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

import system.util

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

And on a button click actionPerformed I run:


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?

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.

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

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.

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.

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

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

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 . 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 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.

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:

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

		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':
	elif level == 'trace':
	elif level == 'debug':
	elif level == 'warn':
	elif level == 'error':
	elif level == 'fatal':
		logger.warn('Unknown level in logMessageHandler')

Then, in some Project Library Script:

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!

1 Like

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