@maeum/logging-controller
v2.2.0
Published
maeum logging controller
Downloads
6
Maintainers
Readme
logging controller
The @maeum/logging-controller
is an implementation of best practices for handling logging in the fastify.js framework. It allows you to pick and choose which logging framework you want to use between winston and pino, and provides standard guidelines when you don't know what to log. It also provides methods for logging richer logs. For example, it takes extra work to include the payload from a FastifyReply to a client in the log, but in @maeum/logging-controller
all I need to do is tell it I want to log it. Use @maeum/logging-controller
to log richer, easier logs!
Why use @maeum/logging-controller
?
- You can choose your favorite package between winston and pino
- Convert
FastifyRequest
to curl so you can quickly reproduce problems when they occur - You can logging the payload of a reply object
- When logging the payload of a reply object, you can compress it with snappy
Getting Started
installation
npm install @maeum/logging-controller --save
Configuration
import { pino as pinoBootstrap, RequestLogger } from '@maeum/logging-controller';
// bootstrap pino logger
pinoBootstrap(false);
const server = fastify()
// pino logger add in fastify by plugin
server.register(RequestLogger.it.plugin, RequestLogger.it);
How to work?
The @maeum/logging-controller
consists of various functions, including functions to initialize winston and pino, functions to extract information for logging from FastifyRequest, and functions to generate curl commands. These functions make it easy for developers to log detailed information while also allowing them to customize the information needed for logging.
flowchart LR
FR[FastifyRequest]
FP[FastifyReply]
WL[winston]
RL[Request<br />Logger]
CC[curl<br />command<br />creator]
subgraph FF[Fastify]
direction TB
FR
FP
FR --- FP
end
FF-->RL
FF-->CC
RL-->WL
CC-->WL