Skip to main content
Version: 3.7.0

Log API

1. Startup Configuration

PropertyValueDefaultRequiredDescription
appIDstringNoneYesApplication ID
uploadAddrHttpstringNoneYesData upload address for HTTP. One of uploadAddrHttp or uploadAddrHttps must be configured. HTTP pages must configure uploadAddrHttp
uploadAddrHttpsstringNoneYesData upload address for HTTPS. One of uploadAddrHttp or uploadAddrHttps must be configured. HTTPS pages must configure uploadAddrHttps
uploadPeriodstring15NoReporting frequency in seconds
enablebooleantrueNoControls SDK activation, enabled by default
debugbooleanfalseNoWhether to enable logger output, debug mode, disabled by default
consoleCollector['log','info','debug','warn','error'][]NoConfigures whether to collect log data from console.log \ info \ debug \ warn \ error, disabled by default
netCollectorbooleanfalseNoConfigures whether to collect network error data, disabled by default
errorCollectorbooleanfalseNoConfigures whether to collect JS error data, disabled by default

Note: If Bonree JS-SDK is used in the page and it cannot be guaranteed that JS-SDK initializes before Log-SDK, do not configure netCollector and errorCollector, as this may cause missing error or network data.

For web applications embedding BonreeLog, initialize and configure the SDK through the start method:

window.BRLog && window.BRLog.start({
appID: "<#AppID#>",
uploadAddrHttp: "http://<#LogUpload Address#>",
uploadAddrHttps: "https://<#LogUpload Address#>",
consoleCollector: ['log','info','debug','warn','error']
})

If BonreeLog is introduced into the project via NPM, initialize and configure it through the BrLogStart method:

import {BRLogStart} from 'bonree-log-jsagent'

......

BrLogStart({
appID: '<#AppID#>',
uploadAddrHttp: 'http://<#LogUpload Address#>',
uploadAddrHttps: 'https://<#LogUpload Address#>',
consoleCollector: ['log','info','debug','warn','error']
})

AppID and LogUpload Address can be obtained from the platform or by contacting technical support.

2. Custom Function Interfaces

Custom Logs

After BonreeLog is successfully initialized, call the relevant APIs on the logger object to directly send log data of different levels to the platform. BonreeLog supports four levels of logs: debug, info, warn, error, with increasing severity.

logger.debug(message, error)
logger.info(message, error)
logger.warn(message, error)
logger.error(message, error)
  • Interface Description
ParameterTypeDescription
messageStringLog data. Required parameter
errorErrorError type. Optional parameter
  • Example
try {
...
throw new Error('Wrong behavior')
...
} catch (error) {
window.BRLog && window.BRLog.logger.error('Error occurred', error)
}

Fully Custom Logs

After BonreeLog is successfully initialized, use the API to directly send custom logs to the platform. Supports custom log levels (debug, info, warn, error), custom log data via message, Error objects, and custom attributes. The attribute parameter only supports objects in {key:value,...} format, and the value should be of string type.

logger.log(level, message, error, attribute)
  • Interface Description
ParameterTypeDescription
levelStringLog level. Only supports one of the four log levels: debug, info, warn, error. Required parameter
messageStringLog data. Required parameter
errorErrorEvent label. Optional parameter
attributeStringAdditional information. Optional parameter
  • Example
try {
...
throw new Error('Minor misbehavior')
...
} catch (error) {
window.BRLog && window.BRLog.logger.log('info', 'Minor misbehavior occurs', error, {JSON: 'JSON parsing failed'})
}

Filter Logs

After BonreeLog is successfully initialized, use the API to set the minimum log level to be recorded. Log data below this level will be filtered. Log levels are: debug < info < warn < error.

setLevel(level)
  • Interface Description
ParameterTypeDescription
levelStringLog level. Only supports one of the four log levels: debug, info, warn, error. Required parameter
  • Example

    After successfully calling the method in the example, debug-level logs in subsequent log data reported to the platform will be filtered. Info, warn, and error-level log data will be reported normally.

window.BRLog && window.BRLog.logger.setLevel('info')

Set Log Prefix

After BonreeLog is successfully initialized, use the API to set the log prefix.

setPrefix(prefix)
  • Interface Description
ParameterTypeDescription
prefixStringLog prefix. Required parameter
  • Example

    After successfully calling the method in the example, subsequent log data reported to the platform will include the "bonree" prefix.

window.BRLog && window.BRLog.setPrefix('bonree')

Add Attribute

After BonreeLog is successfully initialized, use the API to add global log attributes.

addAttribute(key, value)
  • Interface Description
ParameterTypeDescription
keyStringAttribute name. Required parameter
valueStringAttribute value. Required parameter
  • Example
window.BRLog && window.BRLog.addAttribute('original', 'logger')

Remove Attribute

After BonreeLog is successfully initialized, use the API to remove added global log attributes.

removeAttribute(key)
  • Interface Description
ParameterTypeDescription
keyStringAttribute name. Required parameter
  • Example
window.BRLog && window.BRLog.removeAttribute('original')