Report device logs

更新时间:
复制 MD 格式

IoT Platform allows devices to report on-premises logs to the cloud. You can then query these logs and analyze faults in the console.

Note
  • 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"
}
Table 1. Request parameter description
ParameterTypeDescription
idStringThe message ID. It is a string-type number from 0 to 4294967295. The message ID must be unique for the device.
versionStringThe 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.

  • 1: The cloud returns a response.

  • 0: The cloud does not 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.

configScopeStringThe configuration scope. For logs, the only supported dimension is the device. The default value is device.
getTypeStringThe content type to get. The default value is content. Because log configurations are small, the content is returned directly by default.
methodStringThe 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 
        }
    }
}
Table 2. Response parameter description
ParameterTypeDescription
idStringThe message ID. It is a string-type number from 0 to 4294967295. The message ID must be unique for the device.
versionStringThe protocol version number. The only valid value is 1.0.
codeIntegerThe 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.

dataObjectThe result data returned by the cloud.
getTypeStringThe content type to get. The default value is content. Because log configurations are small, the content is returned directly by default.
contentStringThe configuration text content.
modeIntegerThe device log reporting mode. 0: The device SDK does not report logs. 1: The device SDK reports logs.
Table 3. Error messages
Error codeCauseTroubleshooting
6717The 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 Monitoring & O&M > Simple Log Service > On-premises Device Logs page for the instance. Check the value of the getType parameter in the reported data.
6718The 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 Monitoring & O&M > Simple Log Service > On-premises Device Logs 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
        }
    }
}
Table 4. Parameter description
ParameterTypeDescription
idStringThe message ID. It is a string-type number from 0 to 4294967295. The message ID must be unique for the device.
versionStringThe protocol version number. The only valid value is 1.0.
getTypeStringThe content type to get. The default value is content. Because log configurations are small, the content is returned directly by default.
contentStringThe configuration text content.
modeIntegerThe 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"
}
Table 5. Request parameter description
ParameterTypeDescription
idStringThe message ID. It is a string-type number from 0 to 4294967295. The message ID must be unique for the device.
versionStringThe 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.

  • 1: The cloud returns a response.

  • 0: The cloud does not 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.

paramsListThe business parameters of the request. The array can contain up to 40 elements.
utcTimeStringThe 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.
logLevelStringThe log level. You can use the default log levels or define custom ones. The default log levels, from highest to lowest, are:
  • FATAL
  • ERROR
  • WARN
  • INFO
  • DEBUG
moduleStringThe module name:
  • If the device uses the Android SDK, the module name is ALK-LK.
  • If the device uses the C SDK, you must define a custom module name.
  • If the device uses a custom-developed SDK, you must define a custom module name.
codeStringThe 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.

traceContextStringAn optional parameter for context tracking. For a device, use the id of the Alink protocol message. For an app, use the TraceId.
logContentStringThe details of the log content.
methodStringThe request method. The value is thing.log.post.

Alink response data format:

{
    "id" : "123",
    "code":200,
    "data" : {}
}
Table 6. Response parameter description
ParameterTypeDescription
idStringThe message ID. It is a string-type number from 0 to 4294967295. The message ID must be unique for the device.
codeIntegerThe result code. A value of 200 indicates success. Other values indicate failure. For more information, see Device-side general codes.
dataObjectThe result data returned by the cloud. When a device reports log content, the returned result data is empty.