Socket
Book a DemoInstallSign in
Socket

log-agent

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

log-agent

用于监听日志文件变动,并根据需求进行筛选、上报 kafka 或者报警

0.2.1
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

log-agent

build status Test coverage GitHub license node version

NPM

本项目用于监听日志文件变动,可以对于读取到的日志做筛选,可以将日志通过 queue-schedule 或者 @yunnysunny/node-alarm 工具进行日志转发。

安装

yarn add log-agent

测试

npm run test

示例

const LogAgent = require('log-agent');
const NodeAlarm = require('@yunnysunny/node-alarm');
const WXWORK_CONFIG = {
    type: NodeAlarm.ALARM_TYPE_WXWORK,
    options: {
        // 机器人地址
        url: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=637cc457-6e6f-44a5-99ad-2e3d825482b2',
        msgType: 'markdown'//支持 text 和 markdown 两种类型
    }
};
const alarm = new NodeAlarm([WXWORK_CONFIG]);
/*
 * 默认每一行都会作为一个日志实例,输入 mutliLineRegexStart 则支持多行匹配。
 * mutliLineRegexStart 的正则匹配成功后,说明当前日志项还未结束,
 * 直到遇到非 mutliLineRegexContent 正则匹配的行算结束。
 * 
 * 指定 filterRegex 后,当前条目日志只有含有 Error 关键字才会被处理。
 * 
 * 指定 alarm 后,所有 run 函数返回的日志条目,同时也会被通过 alarm 对象发送出去。
 */
const config = {
    logPath:['/app/log/pm2-error-*.log'],
    reportInterval:1000,
    mutliLineRegexStart:'Error',
    mutliLineRegexContent:'at ',
    filterRegex: 'Error',
    alarm
};

const agent = new LogAgent(config);
agent.run(function(err, logs) {
    console.log(logs);
});
//agent.stop();// 停止收集日志

文档

参见这里.

FAQs

Package last updated on 29 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.