Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Make bluebird global
global.Promise = Promise;
// Improve debugging by enabling long stack traces.. it has minimal impact in production
Promise.config({ longStackTraces: true, warnings: false });
// Configure global logger (pino)
// ----------------------------------------------------
const logger = global.logger = pino({ name: 'npms-analyzer' }, process.stdout);
logger.children = {};
// Make sure that changing the level, affects all children
/* eslint-disable no-invalid-this */
logger[pino.symbols.setLevelSym] = wrap(logger[pino.symbols.setLevelSym], function (setLevel, level) {
setLevel.call(this, level);
if (this === logger) {
forIn(logger.children, (child) => { child.level = level; });
}
});
/* eslint-enable no-invalid-this */
// Make some restrictions on the usage of .child()
logger.child = wrap(logger.child, (createChild, bindings) => {
if (!bindings || !bindings.module) {
throw new Error('Expected logger.child to have a module property');
}
if (logger.children[bindings.module]) {
throw new Error(`A logger named ${bindings.module} already exists`);
}
const fixedLogger = function (pinoOptions, destination) {
const logger = Pino({
base: options.name ? {} : null,
serializers: {
err: internals.errSerializer
},
...pinoOptions
}, destination);
// Hack to not log version - will be standard once v6 releases: https://github.com/pinojs/pino/pull/623
logger[Pino.symbols.endSym] = `}${pinoOptions.crlf ? '\r\n' : '\n'}`;
return logger;
};
'use strict'
const pino = require('pino')
const getPrettyStream = require('pino/lib/tools').getPrettyStream
const multistream = require('./multistream')
const {
streamSym,
setLevelSym,
getLevelSym,
levelValSym
} = pino.symbols
function pinoMultiStream (opts, stream) {
if (stream === undefined && opts && typeof opts.write === 'function') {
opts = { stream: opts }
}
const iopts = opts || {}
iopts.stream = iopts.stream || stream || process.stdout // same default of pino
// pretend it is Bunyan
const isBunyan = iopts.bunyan
delete iopts.bunyan
const toPino = Object.assign({}, iopts, { streams: undefined, stream: undefined })
if (Object.prototype.hasOwnProperty.call(iopts, 'streams') === true) {
return fixLevel(pino(toPino, multistream(iopts.streams)))
'use strict'
/**
* Code imported from `pino-http`
* Repo: https://github.com/pinojs/pino-http
* License: MIT (https://raw.githubusercontent.com/pinojs/pino-http/master/LICENSE)
*/
const abstractLogging = require('abstract-logging')
const pino = require('pino')
const { serializersSym } = pino.symbols
const { isValidLogger } = require('./validation')
const {
codes: {
FST_ERR_LOG_INVALID_DESTINATION
}
} = require('./errors')
function createPinoLogger (opts, stream) {
stream = stream || opts.stream
delete opts.stream
if (stream && opts.file) {
throw new FST_ERR_LOG_INVALID_DESTINATION()
} else if (opts.file) {
// we do not have stream
stream = pino.destination(opts.file)
process.on('uncaughtException', (err) => {
logger[pino.symbols.streamSym].flushSync();
throw err;
});