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:
For C# scripts, incorrect references to identifiers can also be found while editing because ULogViewer compiles C# scripts but not JavaScript:
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- Click
at right hand side of toolbar. - Click 'Tools > Script log window' in menu.
- Click 'Tools > Script log window' in menu at top of screen.
View Logs in ULogViewer
- Open a new tab.
- 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:- Critical
- Error
- Warning
- Information
- Debug
- Trace