@mgcrea/fastify-request-logger
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -1,2 +0,2 @@ | ||
import type { FastifyPluginAsync } from 'fastify'; | ||
import type { FastifyPluginAsync, FastifyRequest } from 'fastify'; | ||
export declare type FastifyRequestLoggerOptions = { | ||
@@ -6,3 +6,4 @@ logBody?: boolean; | ||
ignoredPaths?: Array<string>; | ||
ignore?: (request: FastifyRequest) => boolean; | ||
}; | ||
export declare const plugin: FastifyPluginAsync<FastifyRequestLoggerOptions>; |
@@ -9,5 +9,12 @@ "use strict"; | ||
const plugin = async (fastify, options = {}) => { | ||
const { logBody = true, logBindings = { plugin: 'fastify-request-logger' }, ignoredPaths = [] } = options; | ||
const { logBody = true, logBindings = { plugin: 'fastify-request-logger' }, ignoredPaths = [], ignore } = options; | ||
const isIgnoredRequest = (request) => { | ||
const { routerPath } = request; | ||
if (ignoredPaths.includes(routerPath)) { | ||
return true; | ||
} | ||
return ignore ? ignore(request) : false; | ||
}; | ||
fastify.addHook('onRequest', async (request) => { | ||
if (ignoredPaths.includes(request.routerPath)) { | ||
if (isIgnoredRequest(request)) { | ||
return; | ||
@@ -20,3 +27,3 @@ } | ||
fastify.addHook('preHandler', async (request) => { | ||
if (ignoredPaths.includes(request.routerPath)) { | ||
if (isIgnoredRequest(request)) { | ||
return; | ||
@@ -29,3 +36,3 @@ } | ||
fastify.addHook('onResponse', async (request, reply) => { | ||
if (ignoredPaths.includes(request.routerPath)) { | ||
if (isIgnoredRequest(request)) { | ||
return; | ||
@@ -32,0 +39,0 @@ } |
{ | ||
"name": "@mgcrea/fastify-request-logger", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Compact request logger plugin for fastify written in TypeScript", | ||
@@ -26,16 +26,16 @@ "main": "lib/index.js", | ||
"@tsconfig/node10": "^1.0.7", | ||
"@types/ioredis": "^4.19.3", | ||
"@types/node": "^14.14.22", | ||
"@typescript-eslint/eslint-plugin": "^4.14.1", | ||
"@typescript-eslint/parser": "^4.14.1", | ||
"eslint": "^7.18.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-plugin-jest": "^24.1.3", | ||
"@types/ioredis": "^4.22.2", | ||
"@types/node": "^14.14.37", | ||
"@typescript-eslint/eslint-plugin": "^4.20.0", | ||
"@typescript-eslint/parser": "^4.20.0", | ||
"eslint": "^7.23.0", | ||
"eslint-config-prettier": "^8.1.0", | ||
"eslint-plugin-jest": "^24.3.2", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"fastify": "^3.11.0", | ||
"fastify": "^3.14.1", | ||
"jest": "^26.6.3", | ||
"pino-pretty": "^4.3.0", | ||
"pino-pretty": "^4.7.1", | ||
"prettier": "^2.2.1", | ||
"ts-jest": "^26.4.4", | ||
"typescript": "^4.1.3" | ||
"ts-jest": "^26.5.4", | ||
"typescript": "^4.2.3" | ||
}, | ||
@@ -42,0 +42,0 @@ "dependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8444
64