Skip to main content

日志

SDK 会主动收集用户的一些性能和错误日志,开发者可以根据不同的参数来配置哪些日志需要上报,以及上报的日志具体信息。

日志类型

LogType 有以下几种类型:

enum LogType {
  NORMAL = 'normal', // 普通日志类型
  PV = 'pv', // 页面PV
  API = 'api', // API调用
  API_SPEED = 'api_speed', // API测速
  CUSTOM_TIME = 'custom_time', // 自定义测速
  CUSTOM_EVENT = 'custom_event', // 自定义事件
  ASSETS_SPEED = 'assets_speed', // 静态资源测速
  PAGE_PERFORMANCE = 'page_performance', // 页面测速
  WEB_VITALS = 'web_vitals', // web_vitals测速
  SDK_ERROR = 'sdk_error', // sdk错误
SESSION = 'session',
BRIDGE = 'bridge',
WEBSOCKET = 'websocket',
}

不同的 logType 对应的 message 不一样

{
"pv": {
"msg": "spa"
},
"assets_speed": {
"msg": "asset_speed",
"url": "xxxx",
"duration": 4214.3,
"status": 200,
"assetType": "static",
"isHttps": true,
"nextHopProtocol": "",
"urlQuery": "",
"domainLookup": 0,
"connectTime": 0,
"transferSize": -1,
"method": "get"
},
"api": {
"msg": "",
"url": "xxxx",
"status": 200,
"duration": 151,
"method": "POST",
"param": "",
"data": "",
"reqHeaders": "",
"resHeaders": "",
"level": "info",
"ret": "unknown",
"isErr": false,
"trace": "",
"type": "api",
"nextHopProtocol": "",
"plugin": "api"
},
"page_performance": {
"msg": "page_performance",
"type": "page_performance",
"dnsLookup": 0,
"tcp": 0,
"ssl": 0,
"ttfb": 14,
"contentDownload": 1,
"domParse": 125,
"resourceDownload": 4651,
"firstScreenTiming": 1043,
"plugin": "pagePerformance"
},
"web_vitals": {
"type": "web_vitals",
"msg": "web_vitals",
"FCP": 167.5,
"LCP": 761.4000000059605,
"FID": -1,
"CLS": 0.017961352164726968,
"plugin": "webVitals"
},
}

日志等级

logLevel 有以下几种类型:

export enum LogLevel {
INFO = 'info',
ERROR = 'error',
SDK_ERROR = 'sdk_error',
PROMISE_ERROR = 'promise_error',
AJAX_ERROR = 'ajax_error',
SCRIPT_ERROR = 'script_error',
WEBSOCKET_ERROR = 'websocket_error', // websocket错误

IMAGE_ERROR = 'image_error',
CSS_ERROR = 'css_error',
MEDIA_ERROR = 'media_error',

REPORT = 'report',

RET_ERROR = 'ret_error',

BRIDGE_ERROR = 'brige_error',

BLANK_SCREEN = 'blank_screen',

CUSTOM_ERROR = 'custom_error', // 自定义 error

PAGE_NOT_FOUND_ERROR = 'page_not_found_error',
LAZY_LOAD_ERROR = 'lazy_load_error'
}

最终上报格式示例

{
"productId": "xxxx",
"clientIdentify": "xxxx", // string,一次上报的唯一标识
"bean": { "uid": "...", "env": "...", ... },
"ext": { "os": "...", "cpu": "...", ... },
"scheme": "v2",
"d2": [
{
"fields": { "type": "...", "level": "...", ... }, // 后台会更具type和level判断日志类型
"message": [ { ... } ]
}
],
"appKey": "xxxx" // string,产品对应的appKey
"v": "0.0.1"
}