1.0.0 • Published 3 years ago

dl-log v1.0.0

Weekly downloads
86
License
ISC
Repository
-
Last release
3 years ago

安装

npm install dl-log

快速上手

  1. 简单用法
import { LogClass , Enum } from 'dl-log';

// 创建日志采集器
const logs = new LogClass();

// 监听事件
logs.on(Enum.LogErrorIncident.GET_BROWSER_ERROR,(error)=>{
    console.log(error)
})
  1. 标准用法
import { LogClass , Enum } from 'dl-log';

// 创建日志采集器,是否打印采集到的日志信息,printLog:是否抛出异常,noThrowError:如果为:false 的话系统不会因为异常而停止运行
const logs = new LogClass({printLog:true,noThrowError:true});

// 监听事件
logs.on(Enum.LogErrorIncident.GET_BROWSER_ERROR,(error)=>{
    console.log(error)
})
  1. 配置参数
import { LogClass } from 'dl-log';

// 使用方法1  (构造传参)  推荐
new LogClass({printLog:true,noThrowError:true});

// 使用方法2 (调用配置方法传参) 灵活修改
const logs = new LogClass();
logs.injectCustomConfig({printLog:true,noThrowError:true});

API 文档

LogClass

日志采集器

方法参数类型说明
injectCustomConfig( config :LogConfig )LogConfig注入自定义配置
destroyLogErrorEventListener()销毁所有日志监听
on(type: LogErrorIncident, fn:Function)监听日志采集数据

LogConfig

日志配置对象

属性类型说明
noThrowErrorBoolean不抛出异常,让程序继续执行下去。defalut:false
startNodeThrowErrorBoolean启动 node 异常拦截 defalut:false(node 环境)
starBrowserThrowErrorBoolean启动 浏览器 异常拦截 defalut:true(web 环境)
printLogBoolean是否在控制台打印日志 defalut:false

LogErrorIncident

日志异常事件

属性说明
GET_BROWSER_SEVERITY_ERROR浏览器严重异常事件
GET_BROWSER_ERROR浏览器异常事件
GET_NODE_SEVERITY_ERRORnode严重异常事件
GET_NODE_ERRORnode异常事件

LogErrorMessage

采集日志实例信息

属性类型说明
messageString【必填】错误信息
pageString获取页面
urlString获取地址和端口
stackString堆栈信息
linenoNumber错误的行数
filenameString异常代码的文件名
1.0.0

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.4

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.9

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago