
pino
极低开销 的 JavaScript 日志记录器。
文档
运行时
Node.js
Pino 专为在 Node.js 上运行而构建。
Bare
Pino 可在 Bare 上配合 pino-bare 兼容模块使用。
Pear
Pino 可在 Pear 上配合 pino-bare 兼容模块使用,Pear 基于 Bare 构建。
安装
使用 NPM:
$ npm install pino
使用 YARN:
$ yarn add pino
如果您想安装 pino v6,请参阅 https://github.com/pinojs/pino/tree/v6.x。
用法
const logger = require('pino')()
logger.info('hello world')
const child = logger.child({ a: 'property' })
child.info('hello child!')
这将产生:
{"level":30,"time":1531171074631,"msg":"hello world","pid":657,"hostname":"Davids-MBP-3.fritz.box"}
{"level":30,"time":1531171082399,"msg":"hello child!","pid":657,"hostname":"Davids-MBP-3.fritz.box","a":"property"}
有关将 Pino 与 Web 框架配合使用,请参阅:
- Pino with Fastify
- Pino with Express
- Pino with Hapi
- Pino with Restify
- Pino with Koa
- Pino with Node core
http - Pino with Nest
- Pino with Hono
基础
开发格式
pino-pretty 模块可用于
在开发期间格式化日志:

传输与日志处理
由于 Node 的单线程事件循环,强烈建议将发送、 告警触发、重新格式化以及所有形式的日志处理 在单独的进程或线程中进行。
在 Pino 术语中,我们将所有日志处理器称为“传输(transports)”,并建议
使用我们的 pino.transport API 在 worker thread 中运行传输。
更多详情请参阅我们的 Transports⇗ 文档。
低开销
使用最少资源进行日志记录非常重要。日志消息 往往会随时间累积,这可能导致应用程序出现节流效应 ——例如每秒请求数降低。
在许多情况下,Pino 比替代方案快 5 倍以上。
请参阅 Benchmarks 文档以获取对比。
打包支持
Pino 支持使用 webpack 或 esbuild 等工具进行打包。
更多信息请参阅 Bundling 文档。
团队
Matteo Collina
https://www.npmjs.com/~matteo.collina
https://twitter.com/matteocollina
大卫·马克·克莱门茨
https://github.com/davidmarkclements
https://www.npmjs.com/~davidmarkclements
https://twitter.com/davidmarkclem
James Sumners
https://www.npmjs.com/~jsumners
https://twitter.com/jsumners79
托马斯·沃森·斯滕
贡献
Pino 是一个开放开源项目。这意味着:
做出重大且有价值贡献的个人将获得项目的提交权限,以便他们按自己的意愿进行贡献。该项目更像是一个开放的 wiki,而非一个标准的受保护的开源项目。
有关更多详细信息,请参阅 CONTRIBUTING.md 文件。
致谢
本项目由 nearForm 慷慨赞助。 本项目由 Platformatic 慷慨赞助。
标志和形象由 Cosmic Fox Design 设计:https://www.behance.net/cosmicfox.
许可证
根据 MIT 许可。