log
log component: Log component. Used to format message content and record it to logs, supports customizing log format using JavaScript scripts.
JavaScript scripts support ECMAScript 5.1(+) syntax specifications and some ES6 specifications, such as: async/await/Promise/let. Custom Go functions can be called within scripts, please refer to udf.
# Configuration
| Field | Type | Description | Default Value |
|---|---|---|---|
| jsScript | string | Log formatting script | None |
| outputTo | string | Output destination: both/console/logger | both |
jsScript: The JavaScript script used to format log content. This field serves as the body of the following function:function ToString(msg, metadata, msgType, dataType) { ${jsScript} }1
2
3Function parameter descriptions:
- msg: Message content, intelligently converted based on data type
- When
dataType=JSON, type isjsonObject, fields can be accessed usingmsg.field - When
dataType=BINARY, type isUint8Array, byte-level operations are possible - For other dataTypes, type is
string
- When
- metadata: Message metadata, type is
jsonObject - msgType: Message type, type is
string - dataType: Message data type, type is
string(e.g., JSON, TEXT, BINARY, etc.)
The function return value must be of type
string, and the returned string will be recorded as the log content.- msg: Message content, intelligently converted based on data type
outputTo: Log output destination.both(default): output to both the debug console (editor debug output, node logs) and the server logconsole: debug console onlylogger: server log only, with a[chain={chainId} node={nodeId}]prefix on each line for traceability- Any other value fails node initialization
In the editor debug console, log component output and business log events (type=log messages) appear under the same LOG category. To log automatically on node entry/exit without inserting a log node, see Business Log Aspect.
TIP
- The logger can be configured via config.Logger
- Supports configuring log level, output format, etc.
- Supports intelligent processing of multiple data types, including JSON object access and binary data handling
# Data Type Support
This component supports multiple message data types:
- JSON type: Automatically parsed into a JavaScript object, properties can be accessed directly
- BINARY type: Converted to Uint8Array, convenient for byte-level operations
- TEXT type: Remains in string format
- Other types: Uniformly processed as strings
# Relation Type
- Success: Execution successful, message is sent to the
Successchain - Failure: Execution failed, message is sent to the
Failurechain
# Execution Result
This component does not modify the content of msg.Data and msg.Metadata.
# Configuration Examples
# Basic Example
{
"id": "s1",
"type": "log",
"name": "Log Message",
"configuration": {
"jsScript": "return 'Incoming message:\\n' + JSON.stringify(msg) + '\\nIncoming metadata:\\n' + JSON.stringify(metadata);"
}
}
2
3
4
5
6
7
8
# JSON Data Processing Example
{
"id": "s2",
"type": "log",
"name": "Log Temperature",
"configuration": {
"jsScript": "if (dataType === 'JSON' && msg.temperature !== undefined) { return 'Temperature: ' + msg.temperature + '°C, Device: ' + (metadata.deviceId || 'unknown'); } else { return 'Non-JSON message: ' + JSON.stringify(msg); }"
}
}
2
3
4
5
6
7
8
# Binary Data Processing Example
{
"id": "s3",
"type": "log",
"name": "Log Binary Data",
"configuration": {
"jsScript": "if (dataType === 'BINARY') { return 'Binary data length: ' + msg.length + ' bytes, first byte: ' + (msg.length > 0 ? msg[0] : 'empty'); } else { return 'Text message: ' + msg; }"
}
}
2
3
4
5
6
7
8
# Intelligent Multi-Type Processing Example
{
"id": "s4",
"type": "log",
"name": "Intelligent Log Formatting",
"configuration": {
"jsScript": "var prefix = '[' + msgType + '][' + dataType + '] '; switch(dataType) { case 'JSON': return prefix + 'JSON data: ' + JSON.stringify(msg); case 'BINARY': return prefix + 'Binary data: ' + msg.length + ' bytes'; default: return prefix + 'Text data: ' + msg; }"
}
}
2
3
4
5
6
7
8
# Output Destination Example
{
"id": "s5",
"type": "log",
"name": "Server Log Only",
"configuration": {
"jsScript": "return 'Temperature: ' + (dataType === 'JSON' && msg.temperature !== undefined ? msg.temperature : 'n/a');",
"outputTo": "logger"
}
}
2
3
4
5
6
7
8
9