gajus / slonik

A Node.js PostgreSQL client with runtime and build time type safety, and composable SQL.
Other
4.57k stars 139 forks source link

Disable/control roarr logs #277

Closed mmkal closed 3 years ago

mmkal commented 3 years ago

Is it possible to disable the roarr logs? My team are looking into using roarr but there are a lot of logs produced by slonik that we don't want to have to filter out in order to get readable outputs in CloudWatch.

Currently the only workaround I've been able to find is to create a custom global.ROARR_WRITE function which parses the JSON and skips logging if context.package === 'slonik', which seems inefficient and hacky.

Note: both this use case, and the use case of using other loggers than roarr would be solved by passing in a custom logger. I would be happy to update https://github.com/gajus/slonik/pull/158 in order to achieve this.

Edit: not a bug.

gajus commented 3 years ago

You can also create .roarr.js file in your repository and define a filter there.

You should definitely not being doing filtering in the process, though.

Just node your-script.js | roarr. If you are doing just filtering, the process has minimal overhead.

Happy to discuss improvements, whether to Slonik or Roarr, that do not involve replacing the logger.

gajus commented 3 years ago

Nothing actionable here.

gajus commented 3 years ago

Just in case, here is an example of .roarr.js:

https://github.com/gajus/roarr-cli#roarr-configuration-file

mmkal commented 3 years ago

Thanks for the reference! We ended up using pino in the end. I might (re)start a discussion about a way to bring-your-own logger that's palatable at some point! Seems weird that an existing application would have to change loggers when adding slonik.

hjr3 commented 3 years ago

I would like a "bring your own logger" solution as well. We do things like adding a correlation/trace id to our log context so I can view all logs from a particular "trace". The current logging facility does not allow me to do that.

I (think?) I would be fine if we had to confirm to the roarr interface but could pass in our own instance of a roarr logger or some other logger that conforms to the interface.

gajus commented 3 years ago

We do things like adding a correlation/trace id to our log context so I can view all logs from a particular "trace". The current logging facility does not allow me to do that.

What is missing to allow you to do that?

hjr3 commented 3 years ago

I cannot inject the logger. It is created here

gajus commented 3 years ago

correlation/trace id to our log context

How would injecting a logger help here?

yosbelms commented 2 years ago

A more efficient solution could be to allow filter logs before stringified. For that purpose the filter should be part of Roarr logger instead of Roarr cli.

I find elegant to use an env variable with Liqe filter, eg: ROARR_FILTER='NOT context.package:slonik'. The disadvantage of this approach is the Liqe dependency, but it can be used as peer dependency.

Or just globalThis.ROARR_FILTER = (msg) => ...

Or both

What do you think about this @gajus?

gajus commented 2 years ago

I find elegant to use an env variable with Liqe filter, eg: ROARR_FILTER='NOT context.package:slonik'. The disadvantage of this approach is the Liqe dependency, but it can be used as peer dependency.

The disadvantage of this is that you are using potentially CPU-intensive filtering logic on the same process where your primary application is running.

yosbelms commented 2 years ago

@gajus I agree, I will vote for the second approach globalThis.ROARR.filter = (msg) => ...

gajus commented 2 years ago

You can already do this with globalThis.ROARR.write

yosbelms commented 2 years ago

Sure, but I have to parse the JSON which is CPU-intensive only to filter. Another solution could to pass down to ROARR.write the message without serialize as the second param write = (msg, obj) => ... In this was we can use obj to filter out logs without parsing.