From 50cf9168302d28e23853292ffffc5e33008f1b21 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Tue, 25 Jun 2019 13:36:37 -0500 Subject: [PATCH] Fix: Winston Logger string interpolation --- spec/WinstonLoggerAdapter.spec.js | 51 ++++++++++++++++++++++++++++ src/Adapters/Logger/WinstonLogger.js | 6 +++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/spec/WinstonLoggerAdapter.spec.js b/spec/WinstonLoggerAdapter.spec.js index f6ac3a49b5..c476a06be5 100644 --- a/spec/WinstonLoggerAdapter.spec.js +++ b/spec/WinstonLoggerAdapter.spec.js @@ -43,6 +43,22 @@ describe('info logs', () => { } ); }); + + it('info logs should interpolate string', async () => { + const winstonLoggerAdapter = new WinstonLoggerAdapter(); + winstonLoggerAdapter.log('info', 'testing info logs with %s', 'replace'); + const results = await winstonLoggerAdapter.query({ + from: new Date(Date.now() - 500), + size: 100, + level: 'info', + order: 'desc', + }); + expect(results.length > 0).toBeTruthy(); + const log = results.find( + x => x.message === 'testing info logs with replace' + ); + expect(log); + }); }); describe('error logs', () => { @@ -82,6 +98,21 @@ describe('error logs', () => { } ); }); + + it('error logs should interpolate string', async () => { + const winstonLoggerAdapter = new WinstonLoggerAdapter(); + winstonLoggerAdapter.log('error', 'testing error logs with %s', 'replace'); + const results = await winstonLoggerAdapter.query({ + from: new Date(Date.now() - 500), + size: 100, + level: 'error', + }); + expect(results.length > 0).toBeTruthy(); + const log = results.find( + x => x.message === 'testing error logs with replace' + ); + expect(log); + }); }); describe('verbose logs', () => { @@ -129,4 +160,24 @@ describe('verbose logs', () => { done(); }); }); + + it('verbose logs should interpolate string', async () => { + await reconfigureServer({ verbose: true }); + const winstonLoggerAdapter = new WinstonLoggerAdapter(); + winstonLoggerAdapter.log( + 'verbose', + 'testing verbose logs with %s', + 'replace' + ); + const results = await winstonLoggerAdapter.query({ + from: new Date(Date.now() - 500), + size: 100, + level: 'verbose', + }); + expect(results.length > 0).toBeTruthy(); + const log = results.find( + x => x.message === 'testing verbose logs with replace' + ); + expect(log); + }); }); diff --git a/src/Adapters/Logger/WinstonLogger.js b/src/Adapters/Logger/WinstonLogger.js index 8968e4987a..4ff37bb0c6 100644 --- a/src/Adapters/Logger/WinstonLogger.js +++ b/src/Adapters/Logger/WinstonLogger.js @@ -32,7 +32,11 @@ function configureTransports(options) { { filename: 'parse-server.err', json: true, - format: format.combine(format.timestamp(), format.json()), + format: format.combine( + format.timestamp(), + format.splat(), + format.json() + ), }, options, { level: 'error' }