1.1.0 • Published 10 months ago

meercat v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

MeerCat - NestJS Request Logging Middleware

Meercat

The name comes from the animal, Meerkat, which is always extremely focused on its environment in order to protect its colony, and CAT, the UNIX utility which outputs text.

This is a NestJS middleware that serves a simple yet missing functionality in NestJS : logging HTTP requests and errors, like Morgan with Express. It offers several features like customization and detailed error logging

Install and Usage

npm i meercat

Then, in your main app.module.ts

import { MeercatLoggingMiddleware } from 'meercat';

// Declare the middleware on all routes
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(MeercatLoggingMiddleware).forRoutes('*');
  }
}

Options

Custom Logger

By default, Meercat uses the default NestJS logger, only handling the timestamp a bit differently. You can override this behaviour by providing the token MEERCAT_LOGGER with the desired logger.

MeercatOptions

You can customize the logger behaviour by providing the token MEERCAT_OPTIONS with a MeercatOptions object :

export type MeercatOptions = {
  name?: string;
  logErrorDetails?: boolean; // default true
  blacklisted?: string[]
};

name : Customize the logger name logErrorDetails : logs the query, body and user agent to the console when the request status >= 400. log level: debug blacklisted : a list of keywords, if the keyword is included in the req.baseUrl, the request won't be logged (can be used to prevent clutter)

Example :

  providers: [
    {
      provide: MEERCAT_OPTIONS,
      useValue: { logErrorDetails: false } as MeercatOptions,
    },
  ],
1.1.0

10 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago