npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bonree-log-jsagent

v1.0.1

Published

采集browser中日志数据

Downloads

11

Readme

bonree-log-jsagent

bonreelog用于采集browser中的日志数据,bonreelog可自动采集上报网络错误、js错误、控制台console输出的日志数据及自定义的日志数据。

如何使用

  • 安装

    npm install bonree-log-jsagent --save
  • 导出

    import {BRLogStart} from 'bonree-log-jsagent'
  • 初始配置

    BrLogStart({
        token:'b5a8ce5e-a3a8-11ed-b908-0e832fe4bb04',
        uploadAddrHttp:'http://one-log-controller.bonree.com/logs/v1/upload',
        uploadAddrHttps:'https://one-log-controller.bonree.com/logs/v1/upload'
    })
  • 代码中使用

    window.BRLog&&window.BRLog.logger.info('this is a log from web')

配置

| 属性 | 值 | 默认值 | 必填 | 描述 | | ---------------- | ------------------------------------- | ------ | ---- | ------------------------------------------------------------ | | token | string | 无 | 是 | 账号标识 | | uploadAddrHttp | string | 无 | 是 | 数据上传地址,与uploadAddrHttps需配置其一。http页面需配置uploadAddrHttp | | uploadAddrHttps | string | 无 | 是 | 数据上传地址,与uploadAddrHttp需配置其一。https页面需配置uploadAddrHttps | | uploadPeriod | string | 15 | 否 | 上报频率 单位:秒 | | enable | boolean | true | 否 | 控制探针开启,默认开启 | | debug | boolean | false | 否 | 是否开启logger输出,开启debug模式,默认关闭 | | consoleCollector | ['log','info','debug','warn','error'] | [] | 否 | 配置是否采集console.log| info | debug | warn |error的日志数据,默认关闭 | | netCollector | boolean | false | 否 | 配置是否采集网络错误数据,默认关闭 | | errorCollector | boolean | false | 否 | 配置是否采集JS错误数据,默认关闭 |

注:如果页面中使用了bonree的js探针,且无法保证js探针在log之前初始化,请勿配置netCollector和errorCollector,否则将导致error或network数据缺失

日志级别

| level | status | | ----- | ------ | | debug | 0 | | info | 1 | | warn | 2 | | error | 3 |

用法

自定义日志

bonreeLog初始化成功后,使用API直接向平台发送自定义日志,支持传入message自定义日志数据,支持传入Error对象

logger.debug | info | warn | error (message: string,error?: Error)
用例
try {
  ...
  throw new Error('Wrong behavior')
  ...
} catch (error) {
  window.BRLog&&window.BRLog.logger.error('Error occurred', error)
}
完全自定义日志

bonreeLog初始化成功后,使用API直接向平台发送自定义日志,支持自定义日志级别(debug、info、warn、error),支持传入message自定义日志数据,支持传入Error对象,支持自定义属性attribute,attribute仅支持传入{key:value,...}格式对象

logger.log (level:'debug'|'info'|'warn'|'error', message: string ,error?: Error ,attribute?:object)
用例
try {
  ...
  throw new Error('Minor misbehavior')
  ...
} catch (error) {
  window.BRLog&&window.BRLog.logger.log('info', 'Minor misbehavior occurs',error,{JSON:'JSON parsing failed'})
}

高级用法

过滤日志

bonreeLog初始化成功后,使用 API 设置记录的最低日志级别,低于该日志级别的日志数据将被过滤

setLevel (level: 'debug' | 'info' | 'warn' | 'error')
用例
 window.BRLog&&window.BRLog.logger.setLevel('info')
设置日志前缀

bonreeLog初始化成功后,使用 API 设置日志前缀名

setPrefix('bonree')
用例
window.BRLog&&window.BRLog.logger.setPrefix('bonree')
添加属性

bonreeLog初始化成功后,使用 API 记录添加全局日志属性

addAttribute(key:string,value:string)
用例
 window.BRLog&&window.BRLog.addAttribute('original','logger')
移除属性

bonreeLog初始化成功后,使用 API 记录移除全局日志属性

removeAttribute(key:string)
用例
window.BRLog&&window.BRLog.removeAttribute('original')