pinojs / pino-elasticsearch

🌲 load pino logs into Elasticsearch
MIT License
179 stars 67 forks source link

using with pino in browser #86

Closed bjornicus closed 3 years ago

bjornicus commented 3 years ago

I'm trying to produce elastic format logs using pino in the browser, but this plugin doesn't seem to work in that context. it seems only the timestamp function from ecsPinoOptions is called; no other output is modified.

Is this a known or intentional limitation?

mcollina commented 3 years ago

This is intentional and not supported.

bjornicus commented 3 years ago

Thanks for the quick response. I was hoping to produce ecs format logs from the browser and post them to a fluentd http endpoint to ship them to elastic, so was hoping to leverage this plugin to produce properly structured logs. Looks like I'll have to do the transformation myself, but I wouldn't mind adding it to this plugin and submitting a pull request if there's interest in having that support. Or maybe you want to keep it scoped to node only, that's fine too (in which case mentioning it in the readme wings be nice).

Or maybe I'm thinking about the problem wrong, and there's a better approach to client side log collection into elastic.

mcollina commented 3 years ago

The usual flow I have done is to send those logs to a REST endpoint and send them to Elastic afterwards.

bjornicus commented 3 years ago

Right, I've got fluentd as the REST endpoint, but it would be most convenient to accept already ECS format logs, hence my desire produce ECS formatted logs on the client.

Looking more at the pino-elasticsearch code though, most of what it does is maybe not relevant in the browser context and I really just need to post something with a "@timestamp" field (with appropriate timestamp format), "log.level" field, and "message" field and post that. That aught to be fairly trivial and maybe not something that would make a good addition to this plugin; I'm not sure there's a lot of overlap between people that want that and those that want to use it in nodejs.

mcollina commented 3 years ago

I think having some way to provide that for pino browser would be amazing, but it won't fit this module. If you'd like to create one, we'll list inside the pino docs. It might be that you'd need to change a few things in the pino browser implementation as well to have that level of customization needed.