Skip to content

Commit

Permalink
Fix: Winston Logger string interpolation (#5729)
Browse files Browse the repository at this point in the history
  • Loading branch information
dplewis authored Jun 25, 2019
1 parent 5bc79cc commit e08f4f8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
51 changes: 51 additions & 0 deletions spec/WinstonLoggerAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});
6 changes: 5 additions & 1 deletion src/Adapters/Logger/WinstonLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down

0 comments on commit e08f4f8

Please sign in to comment.