Skip to content

BenjaminLindberg/fastify-logger

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@fastify/one-line-logger

@fastify/one-line-logger helps you format fastify's log into a nice one line message:

YYYY-MM-dd HH:mm:ss.SSSTZ - <level> - <method> <route path> - <message>

A standard incoming request log line like:

{"level": 30,"time": 1660151282194,"pid": 1557,"hostname": "foo","reqId": "req-1","req": {"method": "GET","url": "/path","hostname": "localhost:8080","remoteAddress": "127.0.0.1"},"msg": "incoming request"}

Will format to:

2022-08-11 01:08:02.194+0100 - info - GET / - incoming request

Install

npm i @fastify/one-line-logger

Getting started

const server = fastify({
  logger: {
    transport: {
      target: "@fastify/one-line-logger",
    },
  },
});

Custom levels

Custom levels could be used by passing it into logger opts

const server = fastify({
  logger: {
    transport: {
      target: "@fastify/one-line-logger",
    },
    customLevels: {
      foo: 35,
      bar: 45,
    },
  },
});

server.get("/", (request, reply) => {
  request.log.info("time to foobar");
  request.log.foo("FOO!");
  request.log.bar("BAR!");
  reply.send({ foobar: true });
});

License

MIT License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 93.8%
  • TypeScript 6.2%