fastify / one-line-logger

Helps you format fastify's log into a nice one line message
MIT License
32 stars 7 forks source link

feat: custom format log #33

Closed RodrigoDornelles closed 7 months ago

RodrigoDornelles commented 7 months ago

Prerequisites

🚀 Feature Proposal

ability to change the format of the logs

Motivation

I'm working on standardizing logs at my work, and I chose to choose line protocol from influxdb, if there is a field for me to pass a custom function I would be able to do it well!

Example

const server = fastify({
  logger: {
    transport: {
      target: "@fastify/one-line-logger",
    },
    customLevels: {
      foo: 35,
      bar: 45,
    },
    format: (log) => `${log.level.name} error="${log.message}" ${(new Date).getTime()/1000}` 
  },
});
mcollina commented 7 months ago

I think you'd need to create your own transport for that. You can use this repo as the template.