Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Winston Logger string interpolation #5729

Merged
merged 2 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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