Report device logs
IoT Platform allows devices to report on-premises logs to the cloud. You can then query these logs and analyze faults in the console.
- Devices that use the following Link SDKs can report on-premises logs. You can also develop a custom SDK that includes this feature.
- On the Device Details page, turn on the Report On-premises Device Logs switch. The device can then report its on-premises logs to the cloud.
For more information about how to query on-premises device logs, see On-premises device logs.
Get log configurations
Data uplinking.
- Request topic:
/sys/${productKey}/${deviceName}/thing/config/log/get. - Response topic:
/sys/${productKey}/${deviceName}/thing/config/log/get_reply.
Alink request data format:
{
"id" : "123",
"version":"1.0",
"sys":{
"ack":0
},
"params" : {
"configScope":"device",
"getType":"content"
},
"method":"thing.config.log.get"
}| Parameter | Type | Description |
| id | String | The message ID. It is a string-type number from 0 to 4294967295. The message ID must be unique for the device. |
| version | String | The protocol version number. The only valid value is 1.0. |
sys | Object | Parameters for extended features. It contains fields for different features. Note If you use a device-side software development kit (SDK) for development and do not set extended features, this parameter is not included. The related features use default configurations. |
ack | Integer | An extended feature field under sys. It specifies whether to return a response.
Important For information about how to configure this feature, see Thing Specification Language model usage examples. If this feature is not configured, this parameter is not included. The cloud returns a response by default. |
| configScope | String | The configuration scope. For logs, the only supported dimension is the device. The default value is device. |
| getType | String | The content type to get. The default value is content. Because log configurations are small, the content is returned directly by default. |
| method | String | The request method. The value is thing.config.log.get. |
Alink response data format:
{
"id":"123",
"version":"1.0",
"code":200,
"data" :{
"getType":"content",
"content":{
"mode":0
}
}
}| Parameter | Type | Description |
| id | String | The message ID. It is a string-type number from 0 to 4294967295. The message ID must be unique for the device. |
| version | String | The protocol version number. The only valid value is 1.0. |
| code | Integer | The result code. A value of 200 indicates success. Other values indicate failure. For information about the error codes 6717 and 6718, see the error message table below. For other result codes, see Device-side general codes. |
| data | Object | The result data returned by the cloud. |
| getType | String | The content type to get. The default value is content. Because log configurations are small, the content is returned directly by default. |
| content | String | The configuration text content. |
| mode | Integer | The device log reporting mode. 0: The device SDK does not report logs. 1: The device SDK reports logs. |
| Error code | Cause | Troubleshooting |
| 6717 | The value of the getType parameter in the request is invalid. For device logs, only content is supported. | In the IoT Platform console, go to the page for the instance. Check the value of the getType parameter in the reported data. |
| 6718 | The value of the configScope parameter in the request is invalid. For device logs, only device is supported. | In the IoT Platform console, go to the page for the instance. Check the value of the configScope parameter in the reported data. |
Receive log configurations pushed from the cloud
Data downlink
Topic: /sys/${productKey}/${deviceName}/thing/config/log/push.
Alink configuration push data format:
{
"id":"123",
"version":"1.0",
"params" :{
"getType":"content",
"content":{
"mode":0
}
}
}| Parameter | Type | Description |
| id | String | The message ID. It is a string-type number from 0 to 4294967295. The message ID must be unique for the device. |
| version | String | The protocol version number. The only valid value is 1.0. |
| getType | String | The content type to get. The default value is content. Because log configurations are small, the content is returned directly by default. |
| content | String | The configuration text content. |
| mode | Integer | The device log reporting mode. 0: The device SDK does not report logs. 1: The device SDK reports logs. |
Report log content
This is an upstream request.
- Request topic:
/sys/${productKey}/${deviceName}/thing/log/post. - Response topic:
/sys/${productKey}/${deviceName}/thing/log/post_reply.
Alink request data format:
{
"id" : "123",
"version":"1.0",
"sys":{
"ack":0
},
"params" :[{
"utcTime": "2020-03-06T15:15:27.464+0800",
"logLevel": "ERROR",
"module": "ModuleA",
"code" :"4103",
"traceContext": "123456",
"logContent" : "some log content"
}],
"method" : "thing.log.post"
}| Parameter | Type | Description |
| id | String | The message ID. It is a string-type number from 0 to 4294967295. The message ID must be unique for the device. |
| version | String | The protocol version number. The only valid value is 1.0. |
sys | Object | Parameters for extended features. It contains fields for different features. Note If you use a device-side software development kit (SDK) for development and do not set extended features, this parameter is not included. The related features use default configurations. |
ack | Integer | An extended feature field under sys. It specifies whether to return a response.
Important For information about how to configure this feature, see Thing Specification Language model usage examples. If this feature is not configured, this parameter is not included. The cloud returns a response by default. |
| params | List | The business parameters of the request. The array can contain up to 40 elements. |
| utcTime | String | The time when the log was collected. This is the device's local UTC time, including time zone information. The time is in milliseconds and the format is "yyyy-MM-dd'T'HH:mm:ss.SSSZ". You can report other string formats, but this is not recommended because it makes troubleshooting difficult. |
| logLevel | String | The log level. You can use the default log levels or define custom ones. The default log levels, from highest to lowest, are:
|
| module | String | The module name:
|
| code | String | The result status code. It is a string-type number. The error code can be one generated by the device-side SDK (Android SDK error codes and C SDK error codes) or a custom status code. |
| traceContext | String | An optional parameter for context tracking. For a device, use the id of the Alink protocol message. For an app, use the TraceId. |
| logContent | String | The details of the log content. |
| method | String | The request method. The value is thing.log.post. |
Alink response data format:
{
"id" : "123",
"code":200,
"data" : {}
}| Parameter | Type | Description |
| id | String | The message ID. It is a string-type number from 0 to 4294967295. The message ID must be unique for the device. |
| code | Integer | The result code. A value of 200 indicates success. Other values indicate failure. For more information, see Device-side general codes. |
| data | Object | The result data returned by the cloud. When a device reports log content, the returned result data is empty. |