阿克西奥斯·洛格(Axios Logger)
关于
@gcoreplus/axios-logger 是一个轴截取器,可以在与服务器通信时登录显示必要信息的请求/答复数据.
受到 轴距
安装
安装主 lib
npm install --save @gcoreplus/axios-logger
使用量
import axios from 'axios';
import * as AxiosLogger from '@gcoreplus/axios-logger';
const instance = axios.create();
instance.interceptors.request.use(AxiosLogger.requestLogger, AxiosLogger.errorLogger);
instance.interceptors.response.use(AxiosLogger.responseLogger, AxiosLogger.errorLogger);
配置
自定义请求/错误输出日志样本
const instance = axios.create();
instance.interceptors.request.use(
(request) => AxiosLogger.requestLogger(request, { logger: console.log }),
(error) => AxiosLogger.errorLogger(error, { logger: console.error })
);
自定义输出日志构建器样本
import * as AxiosLogger from '@gcoreplus/axios-logger';
AxiosLogger.setGlobalConfig({
logger: console.log,
createLoggerBuilder: config => new ObjectLoggerBuilder(config)
});
| 财产 | 类型 | 默认 | 说明 |
|---|---|---|---|
method | 布尔 | true | 是否包含 HTTP 方法 . |
url | 布尔 | true | 是否包含 URL . |
params.apply | 布尔 | true | 是否包含 HTTP 参数 . |
params.redact | 编辑选项 | undefined | 是否在打印前过滤限制来自参数对象的数据 . |
data.apply | 布尔 | true | 是否包括请求/答复数据. |
data.redact | 编辑选项 | undefined | 是否在打印前过滤限制数据对象的数据 . |
headers.apply | 布尔 | false | 是否包含 HTTP 信头 . |
headers.redact | 编辑选项 | undefined | 是否在打印前过滤来自信头对象的数据 . |
status | 布尔 | true | 是否包含响应状态 . |
prefixText | 字符串% 1 false | 'Axios' | false 没有前缀, 否则, 定制要的前缀 . |
dateFormat | 日期格式 | false | new Date().toISOString() | false 没有时间戳,否则,自定义格式 |
logger | 函数 < 字符串, 任何 > | console.log | 允许用户自定义要使用的日志函数 。 例如,温斯顿 logger.info 可以这样利用: logger.info.bind(this) |
createLoggerBuilder | 函数 QQ 调试器 | new StringLoggerBuilder(config) | 允许自定义日志输出 。 可能的数值, new StringLoggerBuilder(config) 财务报告和审定财务报表 new ObjectLoggerBuilder(config) |
以快取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取重取
@gcoreplus/axios-logger 使用快速编辑处理限制数据
编辑配置示例
import * as AxiosLogger from '@gcoreplus/axios-logger';
AxiosLogger.setGlobalConfig({
headers: {
apply: true,
redact: {
paths: ['["my-token"]', 'cookie'],
censor: '***'
}
}
});
备份
许可证
根据ISC许可证分发。 见 LICENSE 更多信息.
鸣谢
版权所有 2020 g CorePlus Inc.