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