Accessing Diagnostic Logs in Perspective

I would like to display the diagnostic logs from the gateway into a perspective container. Is this possible? I was not able to find a function that does this in the manual nor did I find anything on the exchange.

1 Like

No can do natively. You probably won't be able to nest it inside an iframe either. You'll likely have to read the wrapper log file and display that

I figured that was the only answer but doesn't hurt to ask, thanks.

From the gateway context (e.g. via system.util.getContext) you can get the logging manager and then query for log events; this will be the same view of log events provided by the logging web interface, and thus is missing anything logged to stdout or stderr of the Java process, which is captured in the wrapper log.

So, pros: more direct and structured access, cons: less events visible.

4 Likes

Hi Paul,

Would you please illustrate a bit more in detail how this function can be achieved?
Is it to prepare the script in gateway event to query the log details?

  1. It is possible to display the gateway log viewer (https://[ipaddress]/web/status/diag.logviewer) through a Perspective Inline Frame component. In my implementation I had Config > Security > General > Status Page Permissions left blank (public security level). I am not exactly sure what obstacles a more restricted security setup might introduce.
  2. It appears very possible to retrieve logger information (as suggested by @paul-griffith) and potentially build your own log viewer in Perspective . Here is a starting point I derived from code provided by @kgamble (and left here for my own future reference).
from com.inductiveautomation.ignition.gateway import IgnitionGateway
from com.inductiveautomation.ignition.common.logging import LogQueryConfig
	
loggingManager = IgnitionGateway.get().getLoggingManager()
	
logQueryConfigBuilder = LogQueryConfig.newBuilder()
# May add filters to LogQueryConfigBuilder object

logQueryFilter = logQueryConfigBuilder.build()
# May add filters to LogQueryFilter object

logQueryFilter.setLimit(10)
	
logResults = loggingManager.queryLogEvents(logQueryFilter)
	
logEvents = logResults.getEvents()

events = []
for event in logEvents:
	events.append({
		 'exception' : event.getException()
		,'level'     : event.getLevel()
		,'loggerName': event.getLoggerName()
		,'marker'    : event.getMarker()
		,'message'   : event.getMessage()
		,'properties': event.getProperties()
		,'source'    : event.getSourceLocation()
		,'timestamp' : system.date.fromMillis(event.getTimestamp())
	})

There are lots of filtering options than can be applied using methods available on the LogQueryConfigBuilder and LogQueryConfig class objects.

Screenshot showing gateway log viewer exposed in Perspective Inline Frame component.

It is not retrieving IgnitionGateway Library. But it does import the LogQueryConfig ImportError: cannot import name IgnitionGateway

N.B. that in 8.3 you'll be able to use an API token to authenticate against the same REST API the backend uses to populate the logs form so you don't need the iframe/public access, you can have your Perspective frontend actually fetch the data.

1 Like

Not at a computer right now, but be sure to run this in a perspective view (event script or property binding) and not from the designer script console. The script console in designer runs in a context that is basically equivalent to a Vision client.

1 Like

I have an 8.3 test environment so I'll give it a try.