Gateway Logs - Log Properties

Hi Everyone,

I am pulling gateway logs into a table just fine, but I would like to display a bit more info. Something like the 'log properties' (the little magnifying glass that shows you the project name, device name etc. associated with the message) would be very helpful. Are the message 'log properties' stored somewhere? Can they be queried? As always, any help/info is greatly appreciated.

from com.inductiveautomation.ignition.gateway import IgnitionGateway
from com.inductiveautomation.ignition.common.logging import LogQueryConfig

manager = IgnitionGateway.get().getLoggingManager()

config = LogQueryConfig.newBuilder().build()

results = manager.queryLogEvents(config)
rows = []

for event in results.getEvents():
    properties = event.getProperties()

    rows.append({
        "timestamp": system.date.fromMillis(event.getTimestamp()),
        "level": str(event.getLevel()),
        "loggerName": str(event.getLoggerName()),
        "message": str(event.getMessage()),
        "properties": str(properties) if properties else ""
    })
system.perspective.print("rows"+str(rows))

Use this on Perspective component any Event Action (onStartup, onActionPerformed, onClick ... etc), you can get the log properties, and other data.

Thank you @pratikppatil999 . This worked, however I will need to modify the script to only return the last few log entries. The script here pulled in about 60,000 records at once and crashed my designer. Thanks, again!

config.setLimit(200)

@harrison.m.freeman You can use this to limit the number of records; however, it does not ensure that the returned records are the most recent ones.

Thanks @pratikppatil999 for the update. FYI, I just used the 'sorted()' function to bring in the most recent.