Fix: Logger print JSON and Numbers (#5916)

* Fix: Logger print JSON and Numbers

* fix test
This commit is contained in:
Diamond Lewis
2019-08-13 20:44:03 -05:00
committed by Antonio Davi Macedo Coelho de Castro
parent 4c1be61bed
commit 470bb238b5
3 changed files with 100 additions and 2 deletions

View File

@@ -59,6 +59,38 @@ describe('info logs', () => {
);
expect(log);
});
it('info logs should interpolate json', async () => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('info', 'testing info logs with %j', { hello: 'world' });
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 {"hello":"world"}'
);
expect(log);
});
it('info logs should interpolate number', async () => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('info', 'testing info logs with %d', 123);
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 123'
);
expect(log);
});
});
describe('error logs', () => {
@@ -113,6 +145,38 @@ describe('error logs', () => {
);
expect(log);
});
it('error logs should interpolate json', async () => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('error', 'testing error logs with %j', { hello: 'world' });
const results = await winstonLoggerAdapter.query({
from: new Date(Date.now() - 500),
size: 100,
level: 'error',
order: 'desc',
});
expect(results.length > 0).toBeTruthy();
const log = results.find(
x => x.message === 'testing error logs with {"hello":"world"}'
);
expect(log);
});
it('error logs should interpolate number', async () => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('error', 'testing error logs with %d', 123);
const results = await winstonLoggerAdapter.query({
from: new Date(Date.now() - 500),
size: 100,
level: 'error',
order: 'desc',
});
expect(results.length > 0).toBeTruthy();
const log = results.find(
x => x.message === 'testing error logs with 123'
);
expect(log);
});
});
describe('verbose logs', () => {
@@ -180,4 +244,38 @@ describe('verbose logs', () => {
);
expect(log);
});
it('verbose logs should interpolate json', async () => {
await reconfigureServer({ verbose: true });
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('verbose', 'testing verbose logs with %j', { hello: 'world' });
const results = await winstonLoggerAdapter.query({
from: new Date(Date.now() - 500),
size: 100,
level: 'verbose',
order: 'desc',
});
expect(results.length > 0).toBeTruthy();
const log = results.find(
x => x.message === 'testing verbose logs with {"hello":"world"}'
);
expect(log);
});
it('verbose logs should interpolate number', async () => {
await reconfigureServer({ verbose: true });
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('verbose', 'testing verbose logs with %d', 123);
const results = await winstonLoggerAdapter.query({
from: new Date(Date.now() - 500),
size: 100,
level: 'verbose',
order: 'desc',
});
expect(results.length > 0).toBeTruthy();
const log = results.find(
x => x.message === 'testing verbose logs with 123'
);
expect(log);
});
});