diff --git a/packages/gasket-plugin-fastify/README.md b/packages/gasket-plugin-fastify/README.md index c61ee3253..061b0ac76 100644 --- a/packages/gasket-plugin-fastify/README.md +++ b/packages/gasket-plugin-fastify/README.md @@ -31,6 +31,7 @@ All the configurations for the plugin are added under `fastify` in the config: - `compression`: true by default. Can be set to false if applying compression differently. - `trustProxy`: Enable trust proxy option, [see Fastify documentation for possible values](https://fastify.dev/docs/latest/Reference/Server/#trustproxy) +- `disableRequestLogging`: Turn off request logging, true by default #### Example configuration diff --git a/packages/gasket-plugin-fastify/lib/index.d.ts b/packages/gasket-plugin-fastify/lib/index.d.ts index b2958fffc..2710a48ec 100644 --- a/packages/gasket-plugin-fastify/lib/index.d.ts +++ b/packages/gasket-plugin-fastify/lib/index.d.ts @@ -29,6 +29,8 @@ declare module '@gasket/core' { excludedRoutesRegex?: RegExp; /** Trust proxy configuration */ trustProxy?: FastifyServerOptions['trustProxy']; + /** Fastify request logging per route */ + disableRequestLogging?: boolean; }; /** Middleware configuration */ middleware?: { diff --git a/packages/gasket-plugin-fastify/lib/index.js b/packages/gasket-plugin-fastify/lib/index.js index 1377a0a59..f662f9a05 100644 --- a/packages/gasket-plugin-fastify/lib/index.js +++ b/packages/gasket-plugin-fastify/lib/index.js @@ -21,11 +21,11 @@ const plugin = { actions: { getFastifyApp(gasket) { const { fastify: fastifyConfig = {}, http2, https } = gasket.config; - const { trustProxy = false } = fastifyConfig; + const { trustProxy = false, disableRequestLogging = true } = fastifyConfig; const fastifyLogger = alignLogger(gasket.logger); // @ts-ignore - app ??= fastify({ logger: fastifyLogger, trustProxy, https, http2 }); + app ??= fastify({ logger: fastifyLogger, trustProxy, https, http2, disableRequestLogging }); return app; } diff --git a/packages/gasket-plugin-fastify/test/plugin.test.js b/packages/gasket-plugin-fastify/test/plugin.test.js index 24a7a2261..6e17250e4 100644 --- a/packages/gasket-plugin-fastify/test/plugin.test.js +++ b/packages/gasket-plugin-fastify/test/plugin.test.js @@ -70,7 +70,11 @@ describe('actions', () => { it('does not enable trust proxy by default', async () => { const pluginInstance = require('../lib/index'); await pluginInstance.actions.getFastifyApp(gasket); - expect(mockFastify).toHaveBeenCalledWith({ logger: gasket.logger, trustProxy: false }); + expect(mockFastify).toHaveBeenCalledWith({ + logger: gasket.logger, + trustProxy: false, + disableRequestLogging: true + }); }); it('does enable trust proxy by if set to true', async () => { @@ -78,7 +82,11 @@ describe('actions', () => { const pluginInstance = require('../lib/index'); await pluginInstance.actions.getFastifyApp(gasket); - expect(mockFastify).toHaveBeenCalledWith({ logger: gasket.logger, trustProxy: true }); + expect(mockFastify).toHaveBeenCalledWith({ + logger: gasket.logger, + trustProxy: true, + disableRequestLogging: true + }); }); it('does enable trust proxy by if set to string', async () => { @@ -88,7 +96,29 @@ describe('actions', () => { expect(mockFastify).toHaveBeenCalledWith({ logger: gasket.logger, - trustProxy: '127.0.0.1' + trustProxy: '127.0.0.1', + disableRequestLogging: true + }); + }); + + it('defaults to true for disableRequestLogging', async () => { + const pluginInstance = require('../lib/index'); + await pluginInstance.actions.getFastifyApp(gasket); + expect(mockFastify).toHaveBeenCalledWith({ + logger: gasket.logger, + trustProxy: false, + disableRequestLogging: true + }); + }); + + it('allows request logging if disableRequestLogging is set to false', async () => { + gasket.config.fastify = { disableRequestLogging: false }; + const pluginInstance = require('../lib/index'); + await pluginInstance.actions.getFastifyApp(gasket); + expect(mockFastify).toHaveBeenCalledWith({ + logger: gasket.logger, + trustProxy: false, + disableRequestLogging: false }); }); @@ -96,7 +126,11 @@ describe('actions', () => { const pluginInstance = require('../lib/index'); await pluginInstance.actions.getFastifyApp(gasket); - expect(mockFastify).toHaveBeenCalledWith({ logger: gasket.logger, trustProxy: false }); + expect(mockFastify).toHaveBeenCalledWith({ + logger: gasket.logger, + trustProxy: false, + disableRequestLogging: true + }); }); });