调试器的弹性日志处理器
这个LogHandler通过SDK添加了Elastic的日志.
安装
npm install --save @debugr/elastic
使用量
import { Logger, LogLevel } from '@debugr/core';
import { ElasticHandler } from '@debugr/elastic';
const globalContext = {
applicationName: 'example',
};
const logger = new Logger(globalContext, [
new ElasticHandler({
index: 'example-app-logs',
}),
]);
logger.setContextProperty('jobName', 'elasticTest');
logger.info('Application started.');
// should send a new entry to the `example-app-logs` index with the following content:
// {
// level: 30,
// message: 'Application started.',
// ts: '2022-09-04T12:13:14Z',
// context: {
// applicationName: 'example',
// jobName: 'elasticTest',
// },
// }
选项
这个 ElasticHandler 构造器接受一个 所需经费 options 对象作为第一个参数.
一个实例 Client 类从 @elastic/elasticsearch SDK可以当作第二个
参数; 如果不提供, 构造者将尝试使用所提供的 options
对象。 所以当用一个单一的论据 给建筑师打电话时 options 对象是一个结合
在此定义的日志处理器选项和弹性 Client 选项。 见 @elastic/elasticsearch
可用软件包文档 Client 选项。 处理器本身的现有选项
内容如下:
| 选项 | 类型 | 默认 | 说明 |
|---|---|---|---|
index | string, (中文(简体) ), (entry: LogEntry) => string | (必须) | 发送条目的弹性索引 。 您可以指定一个回调来将每个条目路径到一个基于不同索引,例如基于关卡的索引. |
threshold | LogLevel | LogLevel.ALL | 将登录的条目最低水平 。 此关卡以下的任何条目都将被忽略 . |
bodyMapper | (entry: LogEntry) => Record<string, any> | (见说明) | 调用转换a LogEntry 输入要发送给 Elastic 的数据对象。 除 globalContext 财务报告和审定财务报表 taskContext 将合并为单个对象 context 对象,以及 data 对象将被序列化为 JSON . |
errorCallback | (error: Error) => void | (见说明) | 向 Elastic 发送一个条目时会调用的回调失败 。 默认的回调会简单地将错误记录入控制台. |
errorMsThreshold | number | (无) | 自上次通知以来的最少时间 errorCallback 然后再打电话. |