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

node-logkeep

v1.2.9

Published

Node日志管理

Downloads

22

Readme

node-logkeep

Node日志管理工具

目录表

使用文档

安装

npm install node-logkeep

注册/初始化

const ServerLogger = require('node-logkeep');

const logger = new ServerLogger({
    // APM 采集器地址
    apmAddress: 'http://127.0.0.1',
    // 日志是否写入本地
    localLog: true,
    // 本地日志文件路径.localLog=true时必填
    localDir: './logs/app.log',
    // 业务树,同skywalking service参数
    service: 'test-fron',
    // 业务版本标识,同skywalking serviceVersion
    serviceVersion: 'pc_server_1.0,test-front',
    // 部门标识
    group: 'dept',
    // 子部门标识,部门下的二级标识
    subGroup: 'subdept'
});

ServerLogger(options)options字段说明见初始化参数

日志上报

API:logger.log(logObject, context)

  • logObject:详细字段见日志规范
  • context:上下文信息,可选参数,建议带上
logger.log({
    name: 'var error',
    message: 'a is not a function',
    stack: '',
    grade: 'INFO',
    category: 'defalut'
}, { ctx });

API:logger.info(logInfo, context)

  • logInfo:info日志对象,包含日志名称name和日志信息message两个字段。name是必填字段,message是可选字段,不传入message时默认等于name。
  • context:上下文信息
logger.log({
    name: 'var error',
    message: 'a is not a function',
}, { ctx });

API字段说明

初始化参数

| 字段名称 | 字段类型 | 是否必填 | 说明 | | -- | -- | -- | -- | | apmAddress | string | 否 | 日志采集器地址,不填写则不会自动上报 | | service | string | 是 | 业务树,同skywalking service参数 | | serviceVersion | string | 否 | 业务版本标识,同skywalking serviceVersion。默认与service相同 | | group | string | 是 | 部门标识 | | subGroup | string | 是 | 二级部门标识 | | localLog | boolean | 否 | 是否日志是否需要写入本地日志 | | localDir | string | 否 | 本地日志文件路径,如:./logs/app.log。当localLogtrue时必填 | | sendTime | number | 否 | 日志上报间隔,默认60000(即60s)| | onceUploadLength | number | 否 | 每次上报日志条数,默认10 | | maxQueueLength | number | 否 | 日志队列最大存储条数,默认 1000 |

服务端日志

| 日志字段 | 字段类型 | 是否必填 | 说明 | | -- | -- | -- | -- | | name | string | 是 | 错误名称 | | message | string | 是 | 错误信息 | | stack | string | 否 | 错误堆栈信息 | | category | string | 否 | 错误分类,默认为default | | grade | string | 否 | 日志等级,详见日志级别grade | | context | object | 否 | 上下文信息,最终会转成字符串上报JSON.stringify(obj) |

日志分类category

category内置了以下几个类型的日志,如果不满足需求,也可以根据自身业务定义

| 日志类别 | 说明 | | -- | -- | | defalut | 默认值 | | request | 接口日志 | | frame | 框架层日志信息。如koa app.on('error', haadle) | | business | 业务逻辑日志 | | arg | 参数相关异常 | | authority | 权限类异常日志 | | render | 服务端渲染renderToString日志 | | file | 文件相关类日志 | | service | 依赖服务日志,用于kafkarabbitmq等依赖服务的日志 | | api | 依赖接口异常 | | apiTimeout | 接口超时 | | singleApiTimeout | 单个接口超时。用于扩展apiTimeout,把apiTimeout作为所有接口超时,可以监控到是单个接口超时还是所有接口都超时 |

日志级别grade

| 日志级别 | 说明 | | -- | -- | | FATAL | 最高级别的日志,上报的异常日志可定义为线上P0、P1事故 | | ALERT | 仅次于FATAL的严重错误,但影响面较多(影响人数1000~10000,P2线上事故) | | ERROR | 严重错误,但影响面较小(影响人数<1000,P3+线上事故) | | WARN | 程序出现了不按预期执行的逻辑,但是对用户无影响。如:从本地缓存获取失败,但是兜底从redis获取 | | INFO | 一些自定义日志,程序不存在异常 | | TRACE | 调试日志 |

功能

  • 规范统一的日志收集工具
  • 支持日志自动同步到skywalking