Creating a log and print function that is not working?

Unsure why this is not working, probably some niche reason I am unaware of.

I have two scripts that are involved here,

def universalPrint(message):
	"""	
	Will work for vision or perspective clients now.
	Args:
		message: str, what do you want to print
	Returns:
		None
	"""
	from env import isVision
	if isVision():
		print message
	else:
		import system.perspective
		system.perspective.print(message)

This has works fine and has been use in use for a while.

My new script which is printing, but is not logging, is

def logInfoAndPrint(message, loggerName):
	"""
	For instances where we want to both log to the server but also print to console for easier debugging.
	Args:
		message: anything as we type cast in this function for ease of use, what are we trying to print
		loggerName: str, what logger are we saving this to
	"""
	import system.util
	logger = system.util.getLogger(loggerName)
	universalPrint(str(message))
	universalPrint("about to log")
	logger.info(message)
	universalPrint("logged")

It gets to print the last “logged” statement, but I do not see the actual logged statement in my server logs.

In my console, I see

test message
about to log
09:01:55.877 [AWT-EventQueue-0] INFO test logger - test message
logged

Any ideas whats going on here? Is this not possbile?

From what context are you calling this functions? Client logging writes to the designer console when testing from the designer and i think that is what is shown in your screenshot.
Call the function from a gateway scoped script to write to the gateway log.

2 Likes

I am calling it from key stroke in the live client to test. I know behavior in the script console/designer is not exactly how it works in the client so I am testing it in the client.

If it is a Vision client then the logger will show up in the client diagnostics. If Perspective then it’ll show up at the gateway.

If you want 100% for something to show up in the gateway logs you will need to create a messagehandler and log it from there.

Guess I was mistaken, I thought I had things in the client using system.util.logger to log to the server but on second look I do not. This was just a mistake on my part.

Happens the the best of us. :smiley:

1 Like

Then shouldn’t gateway event scripts logs be available in the gateway logs ?
I can’t figure out how to log anything !
I put a simple

logger = system.util.getLogger("foo")
logger.info("bar")

In a gateway tag change script doesn’t seem to log anything, or at least I can’t seem to be able to find it… This makes debugging quite a difficult task. Any pointer ?

So first things first.

What version of Ignition?

Can you post your entire script you are using and tag setup for this event script? I just tested it on my development system on 8.1.1:

Tag Change Event

The resulting logger from the gateway page:

Don’t use the tag change events on the tags themselves - they are prone to misses and errors. Use the gateway event tag change

An additional benefit is you can funnel multiple tag change events into the same script.

I forget the technicals but this is a safer better approach. Once you set up your tag change event this way, try your changing the tag again, see if you get logs, and if not come back and post your code/setup.

1 Like

version 8.1.1, and the whole script is exactly what you posted, except it’s a gateway event tag change script.
There really is nothing to it, just a simple line of logging, but the output of which I cannot find…

@bkarabinchak.psi : This is indeed how I do it - the value changed event on tags didn’t cut it.

1 Like

Can you post how you have everything setup?
Is the project enabled?
On the gateway page under Status->Gateway Scripts->Tag Change is you tag change script listed there?Any errors? On that page?