# @aligov/retcodelog

> retcode log上报npm包,适用于 browser|nodejs|weex|E应用

Latest version **0.3.5** (published 2021-10-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install @aligov/retcodelog
pnpm add @aligov/retcodelog
yarn add @aligov/retcodelog
bun add @aligov/retcodelog
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.5 |
| Published | 2021-10-26 |
| First published | 2021-10-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 103 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | shenyu.wsy, liunian, tao1991123, itrip, xiazhiqiang, zhousufa, mo.zhou, guoliang.hgl, zwhu, daip, baizhao |
| Keywords | retcode, log |

## Links

- npm: https://www.npmjs.com/package/@aligov/retcodelog
- Repository: git@gitlab.alibaba-inc.com:retcode/log
- npm.io page: https://npm.io/package/@aligov/retcodelog

## Dependencies (1)

- [querystring](https://npm.io/package/querystring.md) ^0.2.0

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 0.3.5 (latest) — 2021-10-26

## README

# retcode log上报脚本

## 通过npm包引用(browser/weex/rax/nodejs/E应用)

> http://web.npm.alibaba-inc.com/package/@ali/retcodelog

1. 引入npm包
```
tnpm install @ali/retcodelog --save
```
2. 在代码中配置,并上报
 
```javascript
var wpo = require('@ali/retcodelog');

// 配置
wpo.setConfig({
    //抽样分母，1代表100%上报，10代表10%上报，100代表1%上报
    sample: 1,
    // spmId必须设置,如果没写默认值,会自动抓页面的spm
    spmId: '', 
    // weex容器内上报必须配置
    request: require('@weex-module/stream').fetch,
    // 取nick name需要用到cookie
    cookie: '',
    // 报错过滤，**符合**特征的会被**过滤**,可设置RegEx,function或string
    errMsgFilter: /(debug)|(testing)/  ,
    // weex request callback,可选，只在weex native环境下有效，response参考
	// [weex文档](http://weex.apache.org/references/modules/stream.html#fetch-options-callback-progresscallback)
	requestCallback: function(response, requestUrl){},
    // 标签，支持String或者Function
    tag: 'new tag'
});

//　上报
wpo.error('testing...');
wpo.retCode('api', true, 100, 'testing api sampling');
```
## [E应用使用retcode文档移步](./README_eapp.md)

> **TIPS**
> 1. 浏览器环境下,借助webpack等工具,也可以引入npm包版本的retcodelog
> 2. weex容器内上报时,必须配置`request = require('@weex-module/stream').fetch`

## 通过cdn地址引用(browser)

> <http://g.alicdn.com/retcode/log/log.js>

1. 配置
```javascript
window.__WPO = {
    config: {
        sample: 100, // 抽样率，100 = 1%，1 = 100%，默认100
        spmId: 'xxx', // spmId
        startTime: xxx, // 自定义测速类页面统计起始时间
        dynamic: true, // 是否启用动态配置
        errMsgFilter: (msg) => {return (/Uncaught Error/.test(msg) && /test/.test(msg));} // 报错过滤，**符合**特征的会被**过滤**,可设置RegEx,function或string
    }
};
```

2. 页面中引入脚本
```html
<script src="//g.alicdn.com/retcode/log/log.js"></script>
```

3. 或者在**引入脚本后**通过`setConfig`接口配置
```javascript
window.__WPO.setConfig({
    sample: 100, // 抽样率，100 = 1%，1 = 100%，默认100
    spmId: 'xxx', // spmId，如果没写默认值，会自动抓页面的spm
    modVal: 1, // 抽样的取值，取模后的数值==该值的认为符合抽样，以页面uid作为基数来抽样，默认1
    startTime: xxx, // 自定义测速类页面统计起始时间
    errMsgFilter: 'testing' // 报错过滤，**符合**特征的会被**过滤**,可设置RegEx,function或string
});
```

4. 上报
```javascript
__WPO.error('testing...');
__WPO.retCode('api', true, 100, 'testing api sampling');
```

> **TIPS**
> 1. `@param dynamic`无法通过`setConfig`来配置
> 2. 地址中加入`wpodebug=1`进入debug模式，强制sampling=1,modVal=1；100%发送请求
> 3. 用户的淘宝昵称会默认上报,userNick来自于cookie中的以下字段`_nk_` | `_w_tb_nick_` | `lgc`
> 4. 通过地址 <http://g.alicdn.com/retcode/log/log.debug.js> 可以引用到未压缩版的log.js用于本地调试日志上报

## demo演示代码
- [浏览器 - cdn引入模式](http://gitlab.alibaba-inc.com/retcode/log/tree/master/demo/browser-cdn)
- [浏览器 - npm包引入模式](http://gitlab.alibaba-inc.com/retcode/log/tree/master/demo/browser-npm)
- [nodejs环境](http://gitlab.alibaba-inc.com/retcode/log/tree/master/demo/nodejs)
- [weex环境](http://gitlab.alibaba-inc.com/retcode/log/tree/master/demo/weex)
- [weex-rx环境](http://gitlab.alibaba-inc.com/retcode/log/tree/master/demo/weex-rx)
- [e应用- npm包引入模式](http://gitlab.alibaba-inc.com/retcode/log/tree/master/demo/eappExample)

## 接口
- [《retcode用户手册》日志上报API定义](http://groups.alidemo.cn/retcode/handbook/_book/senior/log-report.html)

# History
- [HISTORY.md](http://gitlab.alibaba-inc.com/retcode/log/blob/master/HISTORY.md)

---
_Source: https://npm.io/package/@aligov/retcodelog · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
