Fix: Winston Logger string interpolation (#5729)

This commit is contained in:
Diamond Lewis
2019-06-25 18:01:00 -05:00
committed by GitHub
parent 5bc79cc3db
commit e08f4f8023
2 changed files with 56 additions and 1 deletions

View File

@@ -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', () => { 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', () => { describe('verbose logs', () => {
@@ -129,4 +160,24 @@ describe('verbose logs', () => {
done(); 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);
});
}); });

View File

@@ -32,7 +32,11 @@ function configureTransports(options) {
{ {
filename: 'parse-server.err', filename: 'parse-server.err',
json: true, json: true,
format: format.combine(format.timestamp(), format.json()), format: format.combine(
format.timestamp(),
format.splat(),
format.json()
),
}, },
options, options,
{ level: 'error' } { level: 'error' }