Socket
Socket
Sign inDemoInstall

@mgcrea/fastify-request-logger

Package Overview
Dependencies
7
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.3 to 0.3.0

1

lib/plugin.d.ts

@@ -5,3 +5,4 @@ import type { FastifyPluginAsync } from 'fastify';

logBindings?: Record<string, unknown>;
ignoredPaths?: Array<string>;
};
export declare const plugin: FastifyPluginAsync<FastifyRequestLoggerOptions>;

@@ -9,4 +9,7 @@ "use strict";

const plugin = async (fastify, options = {}) => {
const { logBody = true, logBindings = { plugin: 'fastify-request-logger' } } = options;
const { logBody = true, logBindings = { plugin: 'fastify-request-logger' }, ignoredPaths = [] } = options;
fastify.addHook('onRequest', async (request) => {
if (ignoredPaths.includes(request.routerPath)) {
return;
}
const contentLength = request.headers['content-length'];

@@ -17,2 +20,5 @@ request.log.info(logBindings, `${chalk_1.default.bold.yellow('←')}${chalk_1.default.yellow(request.method)}:${chalk_1.default.green(request.url)} request from ip ${chalk_1.default.blue(request.ip)}${contentLength ? ` with a ${chalk_1.default.yellow(contentLength)}-length body` : ''}`);

fastify.addHook('preHandler', async (request) => {
if (ignoredPaths.includes(request.routerPath)) {
return;
}
if (request.body && logBody) {

@@ -23,2 +29,5 @@ request.log.debug({ ...logBindings, body: request.body }, `Request body`);

fastify.addHook('onResponse', async (request, reply) => {
if (ignoredPaths.includes(request.routerPath)) {
return;
}
request.log.info(logBindings, `${chalk_1.default.bold.yellow('→')}${chalk_1.default.yellow(request.method)}:${chalk_1.default.green(request.url)} response with a ${chalk_1.default.magenta(reply.statusCode)}-status`);

@@ -25,0 +34,0 @@ });

2

package.json
{
"name": "@mgcrea/fastify-request-logger",
"version": "0.2.3",
"version": "0.3.0",
"description": "Compact request logger plugin for fastify written in TypeScript",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc