IoT Platform allows devices to submit local logs to the cloud. You can query device logs and troubleshoot problems in the console.

Note
  • Only devices that use the C SDK can submit local logs.
  • To submit device logs, you must go to the Device Details page and turn on the Device local log reporting switch.

For more information about how to query local device logs, see Local device logs.

Devices request log configurations

Upstream data

  • Request topic: /sys/${productKey}/${deviceName}/thing/config/log/get
  • Response topic: /sys/${productKey}/${deviceName}/thing/config/log/get_reply

Alink request format

{
    "id" : 123,
    "version":"1.0",
    "params" : {
        "configScope":"device",  
        "getType":"content"
     },
    "method":"thing.config.log.get"
}
Table 1. Request parameters
Parameter Type Description
id String The ID of the message. Valid values: 0 to 4294967295. Each message ID must be unique for the device.
version String The version of the protocol. Set this parameter to 1.0.
configScope String The scope of log configurations. Only device logs are supported. Default value: device.
getType String The type of the content to be retrieved. Default value: content. The content of log configurations is small in size. By default, all log configurations are returned.
method String The request method. Set the value to thing.property.desired.get.

Alink response format

{
    "id":"123",
    "version":"1.0",
    "code":200,
    "data" :{ 
        "getType":"content",
        "content":{
            "mode":0
        }
    }
}
Table 2. Response parameters
Parameter Type Description
id String The ID of the message. Valid values: 0 to 4294967295. Each message ID must be unique for the device.
version String The version of the protocol. Set this parameter to 1.0.
code Integer The status code in the response. If 200 is returned, the request was successful. If other status codes are returned, the request failed.

For more information about the status codes 6717 and 6718, see the following Table 3. For more information about other status codes, see Common codes returned by devices.

getType String The type of the content to be retrieved. Default value: content. The content of log configurations is small in size. By default, all log configurations are returned.
content String The content of log configurations.
mode Integer The mode that is used to submit device logs. The value 0 indicates that the device SDK is used to submit logs. The value 1 indicates that the device SDK is not used to submit logs.
Table 3. Error messages
Status code Cause Troubleshooting
6717 The getType request parameter is invalid. Device logs support setting the value only to content. Log on to the IoT Platform console. Choose Maintenance > Device Log > Device local log to check the parameter value. You can also view the value of the getType parameter in local device logs.
6718 The configScope request parameters is invalid. Device logs support setting the value only to device. Log on to the IoT Platform console. Choose Maintenance > Device Log > Device local log to check the parameter value. You can also view the value of the configScope parameter in local device logs.

Devices receive log configurations from IoT Platform

Downstream data

Topic: /sys/${productKey}/${deviceName}/thing/config/log/push

Alink data format

{
    "id":"123",
    "version":"1.0",
    "params" :{ 
        "getType":"content",
        "content":{
            "mode":0
        }
    }
}
Table 4. Parameters
Parameter Type Description
id String The ID of the message. Valid values: 0 to 4294967295. Each message ID must be unique for the device.
version String The version of the protocol. Set this parameter to 1.0.
getType String The type of the content to be retrieved. Default value: content. The content of log configurations is small in size. By default, all log configurations are returned.
content String The content of log configurations.
mode Integer The mode that is used to submit device logs. The value 0 indicates that the device SDK is used to submit logs. The value 1 indicates that the device SDK is not used to submit logs.

Devices submit logs

Upstream data

  • Request topic: /sys/${productKey}/${deviceName}/thing/log/post
  • Response topic: /sys/${productKey}/${deviceName}/thing/log/post_reply

Alink request format

{
    "id" : 123,
    "version":"1.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"
}
Table 5. Request parameters
Parameter Type Description
id String The ID of the message. Valid values: 0 to 4294967295. Each message ID must be unique for the device.
version String The version of the protocol. Set this parameter to 1.0.
params List The list of request parameters. The maximum number of array elements is 40.
utcTime String The time when the device collects the log. The time is in UTC and includes the time zone. Unit: milliseconds. Data format: yyyy-MM-dd'T'HH:mm:ss.SSSZ. We recommend that you use this data format for problem troubleshooting.
logLevel String The level of the log. You can use the default log level or customize a log level. The following section lists the default log levels from high to low:
  • FATAL
  • ERROR
  • WARN
  • INFO
  • DEBUG
module String The name of the module, the module name is user-specified.
code String The status code in the response, see Error codes for device SDKs.
traceContext String Optional. The content to be traced. If you are using devices, set this parameter to the value of the id parameter. If you are using applications, set this parameter to the value of the TraceId parameter.
logContent String The content of the log.
method String The request method. Set the value to thing.log.post.

Alink response format

{
    "id" : 123,
    "code":200,
    "data" : {}
}
Table 6. Response parameters
Parameter Type Description
id String The ID of the message. Valid values: 0 to 4294967295. Each message ID must be unique for the device.
code String The status code in the response. If 200 is returned, the request was successful. If other status codes are returned, the request failed. For more information, see Common codes returned by devices.