Winston 3 upgrade (#5496)

*  Release 3.1.3 (#5267)

*  Release 3.1.3

* Update CHANGELOG.md

* ⬆️ Bump winston and winston-daily-rotate-file

Bumps [winston](https://github.com/winstonjs/winston) and [winston-daily-rotate-file](https://github.com/winstonjs/winston-daily-rotate-file). These dependencies needed to be updated together.

Updates `winston` from 2.4.4 to 3.1.0
- [Release notes](https://github.com/winstonjs/winston/releases)
- [Changelog](https://github.com/winstonjs/winston/blob/master/CHANGELOG.md)
- [Commits](https://github.com/winstonjs/winston/compare/2.4.4...3.1.0)

Updates `winston-daily-rotate-file` from 1.7.2 to 3.5.1
- [Release notes](https://github.com/winstonjs/winston-daily-rotate-file/releases)
- [Commits](https://github.com/winstonjs/winston-daily-rotate-file/compare/v1.7.2...v3.5.1)

Signed-off-by: dependabot[bot] <support@dependabot.com>

* Rewrote WinstonLogger to work with winston 3.x api

* Changed winston logger test to use winston-transport

* Added winston-transport dependency

* Close and remove transports before adding them again

* Changed to strict equal

* Override adapter name

* Updated and added getLogs tests

* Bump winston and winston-daily-rotate-file

Bumps [winston](https://github.com/winstonjs/winston) and [winston-daily-rotate-file](https://github.com/winstonjs/winston-daily-rotate-file). These dependencies needed to be updated together.

Updates `winston` from 2.4.4 to 3.2.0
- [Release notes](https://github.com/winstonjs/winston/releases)
- [Changelog](https://github.com/winstonjs/winston/blob/master/CHANGELOG.md)
- [Commits](https://github.com/winstonjs/winston/compare/2.4.4...3.2.0)

Updates `winston-daily-rotate-file` from 1.7.2 to 3.6.0
- [Release notes](https://github.com/winstonjs/winston-daily-rotate-file/releases)
- [Commits](https://github.com/winstonjs/winston-daily-rotate-file/compare/v1.7.2...v3.6.0)

Signed-off-by: dependabot[bot] <support@dependabot.com>

* Fixed tests, updated parse logging

* Fixed tests, better error logging

* Fix failing tests

* Updates as per review
This commit is contained in:
Sam Ilic
2019-04-15 09:03:33 +10:00
committed by Arthur Cinader
parent 943134812e
commit 6ffc41345f
14 changed files with 1018 additions and 1010 deletions

View File

@@ -5,59 +5,58 @@ import DailyRotateFile from 'winston-daily-rotate-file';
import _ from 'lodash';
import defaults from '../../defaults';
const logger = new winston.Logger();
const additionalTransports = [];
const logger = winston.createLogger();
function updateTransports(options) {
const transports = Object.assign({}, logger.transports);
function configureTransports(options) {
const transports = [];
if (options) {
const silent = options.silent;
delete options.silent;
if (_.isNull(options.dirname)) {
delete transports['parse-server'];
delete transports['parse-server-error'];
} else if (!_.isUndefined(options.dirname)) {
transports['parse-server'] = new DailyRotateFile(
if (!_.isNil(options.dirname)) {
const parseServer = new DailyRotateFile(
Object.assign(
{},
{
filename: 'parse-server.info',
name: 'parse-server',
json: true,
},
options,
{ timestamp: true }
)
);
transports['parse-server-error'] = new DailyRotateFile(
parseServer.name = 'parse-server';
transports.push(parseServer);
const parseServerError = new DailyRotateFile(
Object.assign(
{},
{
filename: 'parse-server.err',
name: 'parse-server-error',
json: true,
},
options,
{ level: 'error', timestamp: true }
)
);
parseServerError.name = 'parse-server-error';
transports.push(parseServerError);
}
transports.console = new winston.transports.Console(
Object.assign(
{
colorize: true,
name: 'console',
silent,
},
options
transports.push(
new winston.transports.Console(
Object.assign(
{
colorize: true,
name: 'console',
silent,
},
options
)
)
);
}
// Mount the additional transports
additionalTransports.forEach(transport => {
transports[transport.name] = transport;
});
logger.configure({
transports: _.values(transports),
transports,
});
}
@@ -93,25 +92,27 @@ export function configureLogger({
options.json = true;
options.stringify = true;
}
updateTransports(options);
configureTransports(options);
}
export function addTransport(transport) {
additionalTransports.push(transport);
updateTransports();
// we will remove the existing transport
// before replacing it with a new one
removeTransport(transport.name);
logger.add(transport);
}
export function removeTransport(transport) {
const transportName =
typeof transport == 'string' ? transport : transport.name;
const transports = Object.assign({}, logger.transports);
delete transports[transportName];
logger.configure({
transports: _.values(transports),
});
_.remove(additionalTransports, transport => {
return transport.name === transportName;
const matchingTransport = logger.transports.find(t1 => {
return typeof transport === 'string'
? t1.name === transport
: t1 === transport;
});
if (matchingTransport) {
logger.remove(matchingTransport);
}
}
export { logger };

View File

@@ -48,7 +48,8 @@ export class WinstonLoggerAdapter extends LoggerAdapter {
callback(err);
return reject(err);
}
if (level == 'error') {
if (level === 'error') {
callback(res['parse-server-error']);
resolve(res['parse-server-error']);
} else {

View File

@@ -111,9 +111,12 @@ export class FilesRouter {
res.json(result);
})
.catch(e => {
logger.error(e.message, e);
logger.error('Error creating a file: ', e);
next(
new Parse.Error(Parse.Error.FILE_SAVE_ERROR, 'Could not store file.')
new Parse.Error(
Parse.Error.FILE_SAVE_ERROR,
`Could not store file: ${filename}.`
)
);
});
}

View File

@@ -325,7 +325,7 @@ export function handleParseErrors(err, req, res, next) {
res.status(httpStatus);
res.json({ code: err.code, error: err.message });
log.error(err.message, err);
log.error('Parse error: ', err);
if (req.config && req.config.enableExpressErrorHandler) {
next(err);
}