Scripting in Application

In this article: User-defined scripts are supported by ULogViewer 2.0+. Each script is defined for a specific purpose and will be executed when needed, for example, log analysis. There are 3 scripting languages supported:

Cancellation of Running Script

JavaScript

There is no need to take care of cancellation of running script because cancellation will be handled by JavaScript interpreter.

C# Script and Python

It is the responsibility of the script to check CancellationToken (C#) / is_cancellation_requested() (Python) periodically to abort the running script.
You can also use IsCancellationRequested global property in C# script starting from ULogViewer 3.0.
⬆️ Back to top

Debugging

Syntax Error

The syntax of the script will be checked during editing. Therefore, all syntax errors can be found in the script editing UI:
Syntax Error
For C# scripts, incorrect references to identifiers can also be found while editing because ULogViewer compiles C# scripts but not JavaScript:
Undefined Symbol

Runtime Error

An error dialog will appear when an error occurs while running a script. You can check the error message and the position of the source code that causes the error to find the root cause. Sometimes the position of the source code that causes the error cannot be determined for C# scripts. In this case, you will need to do further debugging via logging.

Open Script Log WindowULogViewer 3.0+

Windows/Linux Users
  1. Click at right hand side of toolbar.
  2. Click 'Tools > Script log window' in menu.
macOS Users
  1. Click 'Tools > Script log window' in menu at top of screen.

View Logs in ULogViewer

  1. Open a new tab.
  2. Select "ULogViewer Real-time Log" log profile.

Error Logs

You can find error log like this while running JavaScript in ULogViewer 3.0+:
Property 'getProperty_' of object is not a function [Line 1, column 0]
Before ULogViewer 3.0:
Error occurred while running analysis script of 'Test Script' (dkj1g2mf): [Line:1, Column:0] Property 'getProperty_' of object is not a function
For C# script, you can find error log like this in ULogViewer 3.0+:
Object reference not set to an instance of an object. [Line 1]
Before ULogViewer 3.0:
Error occurred while running setup script of 'Test Script' (dkj1g2mf): Object reference not set to an instance of an object.
The error message for C# scripts does not contain the position of the source code that causes the error before ULogViewer 3.0. Therefore, you may need to locate the error by logging from the script.
⬆️ Back to top

Logging

Logging is supported while executing a script. For usage of the logger, please refer to Context.Logger for C# script / context.logger for JavaScript / log_*() global functions for Python.
The following log levels are supported, listed from highest priority to lowest:
  1. Critical
  2. Error
  3. Warning
  4. Information
  5. Debug
  6. Trace
In debug mode, logs of all levels will be written to the log buffer and file. Otherwise, only logs with level β‰₯ Debug will be written.
In addition to using the Script log window or the "ULogViewer Real-time Log" log profile to check real-time logs, you can also check the log file by using the "ULogViewer Log File" log profile to load "Log/log.txt" in the root directory of ULogViewer.
⬆️ Back to top