All Products
Document Center

Npm access configuration

Last Updated: Apr 11, 2018


Install alife-logger in the npm warehouse.

npm install alife-logger --save



SDK with BrowerLogger.singleton method.

const BrowerLogger = require('alife-logger');
// BrowserLogger.singleton(conf) conf Import the config configuration
const __bl = BrowerLogger.singleton({
    pid: 'your-project-id',
    imgUrl: '', // Set the log upload path. If it is deployed in Singapore, set it to ``
    // Other config configurations

API description

@static singleton() for single-instance object obtaining

NOTE: This method is applicable only to npm introduction.

Invocation parameter explained: BrowerLogger.singleton(config,prePipe)

As a static method, it returns a single-instance object. The input parameters config and prePipe are valid only for the first invocation. Only instances already generated are returned for subsequent invocation.

Parameter Type Description Required Default value
config Object Site configuration. For other configurations, see configurations of #config. Yes -
prePipe Array Content to be pre-reported No -

You can use this method to initialize SDK at the application entry and obtain the instance during each invocation.

Other reporting APIs

Run BrowerLogger.singleton to obtain the instance.

const __bl = BrowerLogger.singleton();

For instructions on how to use other APIs of __bl, see API user guide.

Config configuration

The Config configuration is the same as the CDN introduction configuration. For more information, see SDK configuration items.


Scenario: Some data must be reported for part of the logic that is executed before calling BrowserLogger.singleton().

const BrowerLogger = require('alife-logger');

// Same as the pipe structure of CDN
const pipe = [
    // The html of the current page is also reported as an API
    ['api', '/index.html', true,, 'SUCCESS'],
    // After SDK is initialized, SPA automatic resolution starts immediately 
    ['setConfig', {enableSPA: true}]

const __bl = BrowserLogger.singleton({pid:'Unique ID of the site'},pipe);

The Pipe data structure is the same as CDN introduction.