pino README

The project's README from github.com/pinojs/pino. As one markdown file: README.md.

banner

pino

npm version Build Status js-standard-style

Very low overhead JavaScript logger.

Documentation

Runtimes

Node.js

Pino is built to run on Node.js.

Bare

Pino works on Bare with the pino-bare compatibility module.

Pear

Pino works on Pear, which is built on Bare, with the pino-bare compatibility module.

Install

Using NPM:

$ npm install pino

Using YARN:

$ yarn add pino

If you would like to install pino v6, refer to https://github.com/pinojs/pino/tree/v6.x.

Usage

const logger = require('pino')()

logger.info('hello world')

const child = logger.child({ a: 'property' })
child.info('hello child!')

This produces:

{"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"}

For using Pino with a web framework see:

Essentials

Development Formatting

The pino-pretty module can be used to format logs during development:

pretty demo

Transports & Log Processing

Due to Node's single-threaded event-loop, it's highly recommended that sending, alert triggering, reformatting, and all forms of log processing are conducted in a separate process or thread.

In Pino terminology, we call all log processors "transports" and recommend that the transports be run in a worker thread using our pino.transport API.

For more details see our Transports⇗ document.

Low overhead

Using minimum resources for logging is very important. Log messages tend to get added over time and this can lead to a throttling effect on applications – such as reduced requests per second.

In many cases, Pino is over 5x faster than alternatives.

See the Benchmarks document for comparisons.

Bundling support

Pino supports being bundled using tools like webpack or esbuild.

See Bundling document for more information.

The Team

Matteo Collina

https://github.com/mcollina

https://www.npmjs.com/~matteo.collina

https://twitter.com/matteocollina

David Mark Clements

https://github.com/davidmarkclements

https://www.npmjs.com/~davidmarkclements

https://twitter.com/davidmarkclem

James Sumners

https://github.com/jsumners

https://www.npmjs.com/~jsumners

https://twitter.com/jsumners79

Thomas Watson Steen

https://github.com/watson

https://www.npmjs.com/~watson

https://twitter.com/wa7son

Contributing

Pino is an OPEN Open Source Project. This means that:

Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.

See the CONTRIBUTING.md file for more details.

Acknowledgments

This project was kindly sponsored by nearForm. This project is kindly sponsored by Platformatic.

Logo and identity designed by Cosmic Fox Design: https://www.behance.net/cosmicfox.

License

Licensed under MIT.

pino (pinojs/pino)

Searching Database…

18.3K ·GitHub
这是什么东西?Pino 是一个开销极低的 JavaScript JSON 日志库。它能在 Node.js 应用内部直接输出结构化的 JSON 日志,同时把性能损耗控制在很低的水平。
它是我在自己代码里调用的库,还是一个需要单独运行的服务?是一个库:通过 npm 或 yarn 安装,然后在你的应用里创建一个日志记录器即可。不需要运行任何服务器或后台进程。
怎么把它加到项目里?用 npm 或 yarn 安装,在代码里引入它,然后就可以开始记录日志了。官方为 Fastify、Express、Hapi、Restify、Koa、Node 核心 http、Nest 和 Hono 提供了现成的集成指南。
它只能在 Node.js 下运行,还是也支持其他运行时?Node.js 是它的目标运行时,不过 README 也提到可以通过 pino-bare 兼容模块支持 Bare 和 Pear。它以普通的 npm 包形式发布。
如果每行日志都是原始 JSON,终端岂不是没法看?这是换取快速、机器可解析输出的代价。开发时可以用 pino-pretty 模块把 JSON 格式化成人类易读的日志。
浏览器端或打包后的代码里也能用吗?可以——有专门的浏览器端 API 文档,而且 Pino 明确支持用 webpack、esbuild 这类工具进行打包。
可以免费使用吗,包括商业项目?可以——Pino 采用 MIT 许可证,任何项目都可以自由使用,商业项目也不例外。
Pino 比其他日志库快多少?README 声称在很多场景下 Pino 比同类方案快 5 倍以上,并链接了一份 Benchmarks 文档提供详细对比。低开销的意义在于:大量的日志记录不会拖慢你应用的每秒请求数。
在生产环境里,日志的传输、格式转换或告警应该怎么处理?不要放在应用的主线程里做:由于 Node 的事件循环是单线程的,README 建议通过 pino.transport API 把所有日志处理都作为 transport 放到 worker 线程中运行。
能把密码这类敏感字段从日志里抹掉吗?可以——README 除了子日志记录器和 transport 之外,还提供了 Redaction API(脱敏接口)的文档,可以从日志输出中移除敏感值。
Creator
pinojs
Size
3.4 MB
Stars
18.3K
Age
10y
Commits · 90 Days