Logger: Fix timestamp and format (#5571)

* remove no-op config of logger

* add a test to check on the timestamp

* add a test to verify that we
get non json console loggging by default

* configure transports to include
timestamps in files

* Add failing test to confirm that WinstonLoggerAdapter
is not filtering on level.

* actually fix the test to refelect the facth that this isn't the problem

* Remove bogus date ranges that are now failing
becuase we have timestamps.
This commit is contained in:
Arthur Cinader
2019-05-09 12:58:54 -07:00
committed by Diamond Lewis
parent 81ecf2fd74
commit 87da62bca2
4 changed files with 62 additions and 21 deletions

View File

@@ -39,6 +39,36 @@ describe('WinstonLogger', () => {
});
});
it('should have a timestamp', done => {
logging.logger.info('hi');
logging.logger.query({ limit: 1 }, (err, results) => {
if (err) {
done.fail(err);
}
expect(results['parse-server'][0].timestamp).toBeDefined();
done();
});
});
it('console should not be json', done => {
// Force console transport
reconfigureServer({
logsFolder: null,
silent: false,
})
.then(() => {
spyOn(process.stdout, 'write');
logging.logger.info('hi', { key: 'value' });
expect(process.stdout.write).toHaveBeenCalled();
const firstLog = process.stdout.write.calls.first().args[0];
expect(firstLog).toEqual('info: hi {"key":"value"}' + '\n');
return reconfigureServer();
})
.then(() => {
done();
});
});
it('should enable JSON logs', done => {
// Force console transport
reconfigureServer({

View File

@@ -66,10 +66,7 @@ describe('LoggerController', () => {
});
it('can process an ascending query without throwing', done => {
// Make mock request
const query = {
from: '2016-01-01Z00:00:00',
until: '2016-01-01Z00:00:00',
size: 5,
order: 'asc',
level: 'error',
@@ -114,10 +111,7 @@ describe('LoggerController', () => {
});
it('can process a descending query without throwing', done => {
// Make mock request
const query = {
from: '2016-01-01Z00:00:00',
until: '2016-01-01Z00:00:00',
size: 5,
order: 'desc',
level: 'error',

View File

@@ -66,6 +66,22 @@ describe('error logs', () => {
}
);
});
it('Should filter on query', done => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('error', 'testing error logs');
winstonLoggerAdapter.query(
{
from: new Date(Date.now() - 500),
size: 100,
level: 'error',
},
results => {
expect(results.filter(e => e.level !== 'error').length).toBe(0);
done();
}
);
});
});
describe('verbose logs', () => {

View File

@@ -1,4 +1,4 @@
import winston from 'winston';
import winston, { format } from 'winston';
import fs from 'fs';
import path from 'path';
import DailyRotateFile from 'winston-daily-rotate-file';
@@ -19,9 +19,9 @@ function configureTransports(options) {
{
filename: 'parse-server.info',
json: true,
format: format.combine(format.timestamp(), format.json()),
},
options,
{ timestamp: true }
options
)
);
parseServer.name = 'parse-server';
@@ -32,27 +32,28 @@ function configureTransports(options) {
{
filename: 'parse-server.err',
json: true,
format: format.combine(format.timestamp(), format.json()),
},
options,
{ level: 'error', timestamp: true }
{ level: 'error' }
)
);
parseServerError.name = 'parse-server-error';
transports.push(parseServerError);
}
transports.push(
new winston.transports.Console(
Object.assign(
{
colorize: true,
name: 'console',
silent,
},
options
)
)
const consoleFormat = options.json ? format.json() : format.simple();
const consoleOptions = Object.assign(
{
colorize: true,
name: 'console',
silent,
format: consoleFormat,
},
options
);
transports.push(new winston.transports.Console(consoleOptions));
}
logger.configure({