Log Analysis Script (JavaScript)
In this article:
Suggest reading Scripting in Application (JavaScript) first to get the basis of scripting.
Sub Scripts
There are 2 sub-scripts for each log analysis script. The context when executing script will be shared across all sub-scripts belong to same script.Script to Setup Analysis
To perform custom actions before analyzing logs. The script will be invoked one time after applying the log analysis script. Example:
context.data["messageRegex"] = new RegExp("ULogViewer");
Script to Analyze Log
Script to be invoked for each log to be analyzed. The returned value should be boolean to indicate whether results added by script should be taken or not. ⬆️ Back to topNamespaces
The following namespaces are imported by default:- System.Text.RegularExpressions as sysTextRegularExpressions
- CarinaStudio.ULogViewer.Logs as csUlvLogsDeprecated in v3.0+
To access types and functions related to log.
-
CarinaStudio.ULogViewer.ViewModels.Analysis.Scripting as csUlvScriptingDeprecated in v3.0+
To access types and functions related to log analysis by script.
CarinaStudio.* namespaces should not be imported manually starting from ULogViewer 3.0. All necessary types will be imported automatically.
⬆️ Back to top
Context
The followings are members of context other than basic members:-
addResult(Result result)
Add analysis result. The followings are members of Result structure:v3.0+
-
beginningLog: ILog
The beginning log which is related to result.
-
byteSize: number
The size in bytes related to result.
-
duration: System.TimeSpan
The duration which is related to result.
-
endingLog: ILog
The ending log which is related to result.
-
log: ILog
The log which is related to result.
-
message: string
Message of result.
-
quantity: number
The quantity which is related to result.
-
type: ResultType
Type of result. Please refer to Type of Analysis Result for possible values.
The followings are constructors of Result before ULogViewer 3.0:-
Result(type: ResultType, message: string, log: ILog)
-
type
Type of result. Please refer to Type of Analysis Result for possible values.
-
message
Message of result.
-
log
The log which is related to result.
-
type
-
Result(type: ResultType, message: string, beginningLog: ILog, endingLog: ILog)
-
type
Type of result. Please refer to Type of Analysis Result for possible values.
-
message
Message of result.
-
beginningLog
The beginning log which is related to result.
-
endingLog
The ending log which is related to result.
-
type
-
beginningLog: ILog
-
Log: ILog
The log to be analyzed. The followings are members of ILog:
-
getProperty(name: string, defaultValue: object): object
Get property of log with specific name. The defaultValue will be returned if property doesn't exist. Please refer to Name of Log Properties for valid names.
-
text: string
Get full text of log. The format of text is same as text for log text filtering.
-
getProperty(name: string, defaultValue: object): object
var regex = context.data["messageRegex"];
var message = context.log.getProperty("Message", null);
if (message != null && regex.test(message))
{
var result = new Result();
result.log = context.log;
result.message = "Log found!!";
result.type = ResultType.information;
context.addResult(result);
return true;
}
return false;
Example before ULogViewer 3.0:
var message = context.log.getProperty("Message", null);
if (message != null && regex.test(message))
{
var result = new Result();
result.log = context.log;
result.message = "Log found!!";
result.type = ResultType.information;
context.addResult(result);
return true;
}
return false;
var regex = context.data["messageRegex"];
var message = context.log.getProperty("Message", null);
if (message != null && regex.test(message))
{
context.addResult(new Result(ResultType.information, "Log found!!", context.log));
return true;
}
return false;
⬆️ Back to top
var message = context.log.getProperty("Message", null);
if (message != null && regex.test(message))
{
context.addResult(new Result(ResultType.information, "Log found!!", context.log));
return true;
}
return false;
Type of Analysis Result
All types of analysis results are defined in ResultType enumeration:- error (Default)
- warning
- operationStart
- operationEnd
- increasev3.0+
- decreasev3.0+
- steadyv3.0+
- fastv3.0+
- slowv3.0+
- checkpoint
- timeSpan
- performance
- frequencyv3.0+
- trendv3.0+
- information
- skippedOperationv3.0+
- debugv3.0+
Name of Log Properties
-
BeginningTimeSpan
Beginning time span. The type is System.TimeSpan.
-
BeginningTimestamp
Beginning timestamp. The type is System.DateTime.
-
Category
Category. The type is string.
-
DeviceId
ID of device. The type is string.
-
DeviceName
Name of device. The type is string.
-
EndingTimeSpan
Ending time span. The type is System.TimeSpan.
-
EndingTimestamp
Ending time span. The type is System.DateTime.
-
Event
Event. The type is string.
- Extra1
- Extra10
- Extra11v4.0+
- Extra12v4.0+
- Extra13v4.0+
- Extra14v4.0+
- Extra15v4.0+
- Extra16v4.0+
- Extra17v4.0+
- Extra18v4.0+
- Extra19v4.0+
- Extra2
- Extra20v4.0+
- Extra3
- Extra4
- Extra5
- Extra6
- Extra7
- Extra8
- Extra9
Extra information. The type is string.
-
FileName
Name of file to read log. The type is string.
-
Level
Level of log. The type is LogLevel defined by ULogViewer. The followings are values defined in LogLevel from the highest priority to the lowest:
- fatal
- error
- failure
- warn
- success
- info
- debug
- trace
- verbose
- undefined
-
LineNumber
Line number. The type is number.
-
Message
Message. The type is string.
-
ProcessId
ID of process. The type is number.
-
ProcessName
Name of process. The type is string.
-
ReadTimev3.0+
Timestamp of log to be read. The type is System.DateTime.
-
SourceName
Name of log source. The type is string.
-
Summary
Summary. The type is string.
-
Tags
Tags. The type is string.
-
ThreadId
ID of thread. The type is number.
-
ThreadName
Name of thread. The type is string.
-
TimeSpan
Time span. The type is System.TimeSpan.
-
Timestamp
Timestamp. The type is System.DateTime.
-
Title
Title. The type is string.
-
UserId
ID of user. The type is string.
-
UserName
Name of user. The type is string.