Logger not logging

Hi All
I have a wired situation. At some areas in scripting, the logger functionality works, but wathever I try to make new, I never get anything to log. Now I tried in the Script console the following code:
logger = system.util.getLogger("test")
logger.error("Hello World")

It runs without any error but there is nothing in the log on the gateway.

How can I trouble shoot this issue?
Thanks for any hint.

Try:

system.perspective.print("Hello")

This is running on your designer, I don't believe it will go to the gateway when called in the script console scope.

1 Like

AttributeError: 'com.inductiveautomation.ignition.designer.gui.tool' object has no attribute 'perspective'

Ups, didn't read that "script console" thing.

Script console is running in your computer. Is like just having a standalone Python installed in your pc. You can't pass logs to the gateway from the script console.

OK, thanks for the information, that makes sense.

The scripting in the script console logs locally as @diamond said and you'll see those logs in the diagnostics of your designer.

I've also written a couple of scripts to force logging to the gateway with this called from Vision and using this instead of the standard logger:

def logToGateway(message, logger='VisionClient', level='info'):
	'''
	Logs a message to the Ignition Gateway instead of the local client logs
	
	Args:
		messsage (str): Message string
		logger (str): Name of logger to log the message under
		level (str): Log Level (fatal, error, warn, info, debug, trace)
		
	'''
	system.util.sendMessage('GatewayScripts', 'LogToGateway', {'message': message, 'logger': logger, 'level': level})

And a Gateway Event Message script "LogToGateway" in a project named "GatewayScripts" with the following:

def handleMessage(payload):
	"""
	
	Payload should include the following dictionary items:
		logger: 	Name of Logger for Gateway Logs
		level: 		Log level (fatal, error, warn, info, debug, or trace)
		message: 	Message to log
		
	"""

	loggerName = 'LogToGateway' if not payload['logger'] else payload['logger']
	level = 'info' if not payload['level'] else payload['level'].lower()
	
	logger = system.util.getLogger(loggerName)
	try:
		if level == 'fatal':
			logger.fatal(payload['message'])
		elif level == 'error':
			logger.error(payload['message'])
		elif level == 'warn':
			logger.warn(payload['message'])
		elif level == 'info':
			logger.info(payload['message'])
		elif level == 'debug':
			logger.debug(payload['message'])
		elif level == 'trace':
			logger.trace(payload['message'])
	except:
		pass

When you need to test code in gateway scope, you might find my Integration Toolkit's system.util.runInGateway decorator handy.

2 Likes