Scripting in Application

In this article: User-defined scripts are supported by ULogViewer 2.0+. Each script is defined for specific purpose and will be executed when needed. For ex, 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 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 script will be checked during editing. Therefore, all syntax error can be found in script editing UI:
Syntax Error
For C# script, incorrect reference to identifier can also be found while editing because ULogViewer do compilation for C# script but not for JavaScript:
Undefined Symbol

Runtime Error

A error dialog will show when error occurred while running script. You can check the error message and the position of source code which causes the error to find the root cause. Sometimes the position of source code which causes the error cannot be determined for C# script. In this case, You will need to do further debugging by 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# script doesn't contain the position of source code which causes the error before ULogViewer 3.0. Therefore, you may need to find error by logging from script.
⬆️ Back to top

Logging

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