pinojs/pino-elasticsearch là dự án JavaScript với 193 sao. 🌲 load pino logs into Elasticsearch
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
pino-elasticsearch
To send pino logs to elasticsearch:
cat log | pino-elasticsearch --node http://localhost:9200
Flags
-h | --help Display Help
-v | --version display Version
-n | --node the URL where Elasticsearch is running
-i | --index the name of the index to use; default: pino
will replace %{DATE} with the YYYY-MM-DD date
-t | --type the name of the type to use; default: log
-f | --flush-bytes the number of bytes for each bulk insert; default: 1000
-t | --flush-interval time that the helper will wait before flushing; default: 30000
-l | --trace-level trace level for the elasticsearch client, default 'error' (info, debug, trace).
| --es-version specify the major version number of Elasticsearch (eg: 5, 6, 7)
(this is needed only if you are using Elasticsearch <= 7)
-u | --username Username to specify with authentication method
(can only be used in tandem with the 'password' flag)
-p | --password Password to specify with authentication method
(can only be used in tandem with the 'username' flag)
-k | --api-key Api key for authentication instead of username/password combination
-c | --cloud Id of the elastic cloud node to connect to
-r | --read-config the name of config file
--rejectUnauthorized Reject any connection which is not authorized with the list of supplied CAs; default: true
--opType the op_type to use (create, index)
"create" is required when using datastreams
Using multiple streams (output to Console and Elasticsearch)
If you want to output to multiple streams (transports and console), you can either use pino.transport or pino.multistream. Transport is recommended and can be used like:
Please note: The options must be serializable. For example if you use a function as index, you will get an error. Find an example at pino-pretty how you can use it.
Custom Connection
If you want to use a custom Connection class for the Elasticsearch client, you can pass it as an option when using as a module. See the Elasticsearch client docs for Connection.
Assuming your Elasticsearch instance is running and accessible, there are a couple of common problems that will cause indices or events (log entries) to not be created in Elasticsearch when using this library. Developers can get feedback on these problems by listening for events returned by the stream handler.
The stream handler returned from the default factory function is an EventEmitter. Developers can use this interface to debug issues encountered by the pino-elasticsearch library.
The bulk insert request to Elasticsearch failed (records dropped).
insert
(stats: Record<string, any>) => void
Called when an insert was successfully performed
error
(error: Error) => void
Called when the Elasticsearch client fails for some other reason
There are a few common problems developers will encounter when initially using this library. The next section discusses these issues.
Pino output is not JSON
Any transform of the stream (like pino-pretty) that results in an non-JSON stream output will be ignored (the unknown event will be emitted).
const pino = require('pino');
const pinoElastic = require('pino-elasticsearch');
const streamToElastic = pinoElastic({
index: 'an-index',
node: 'http://localhost:9200',
esVersion: 7,
flushBytes: 1000
})
streamToElastic.on(
'unknown',
(line, error) =>
console.log('Expect to see a lot of these with Pino Pretty turned on.')
);
const logger = pino({
prettyPrint: true,
}, streamToElastic)
Events do not match index schema/mappings
Elasticsearch schema mappings are strict and if events do not match their format, the events will be dropped. A typical example is if you use the default pino format with the logs- index in Elasticsearch. The default installation of Elasticsearch includes a data pipeline mapped to the logs- index prefix. This is intended to be used by the Beats and Logstash aggregators and requires @timestamp and @message fields. The default pino setup uses time and msg. Attempting to write events to the logs- index without mapping/transforming the pino schema will result in events being dropped.
Developers can troubleshoot insert errors by watching for the insertError event.
You can then use Kibana to
browse and visualize your logs. Note: This transport works only with Elasticsearch version ≥ 5.
Dynamic index
It is possible to customize the index name for every log line just providing a function to the index option:
const pino = require('pino')
const pinoElastic = require('pino-elasticsearch')
const streamToElastic = pinoElastic({
index: function (logTime) {
// the logTime is a ISO 8601 formatted string of the log line
return `awesome-app-${logTime.substring(5, 10)}`
},
node: 'http://localhost:9200'
})
// ...
The function must be sync, doesn't throw and return a string.
Datastreams
Indexing to datastreams requires the opType to be set to create:
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/pinojs/pino-elasticsearch là nguồn chính thức.
pinojs/pino-elasticsearch có phải mã nguồn mở không?
Có — pinojs/pino-elasticsearch phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/pinojs/pino-elasticsearch.
pinojs/pino-elasticsearch có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho pinojs/pino-elasticsearch. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
pinojs/pino-elasticsearch dùng license gì?
pinojs/pino-elasticsearch phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
pinojs/pino-elasticsearch là gì?
pinojs/pino-elasticsearch (pinojs/pino-elasticsearch) là dự án JavaScript trên GitHub. Theo mô tả gốc: 🌲 load pino logs into Elasticsearch
Đọc đầy đủ README ở tab phía trên.
Chưa chắc pino-elasticsearch có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về pino-elasticsearch.