Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
opts.host = option.optarg;
break;
case 'k':
opts.keyPath = option.optarg;
break;
case 'u':
opts.url = url.parse(option.optarg).href;
break;
case 'v':
// Allows us to set -vvv -> this little hackery
// just ensures that we're never < TRACE
LOG.level(Math.max(bunyan.TRACE, (LOG.level() - 10)));
if (LOG.level() <= bunyan.DEBUG)
LOG = LOG.child({src: true});
break;
default:
process.exit(1);
break;
}
}
if (!opts.url && !process.env.MANTA_URL)
usage('url is a required argument');
if (!opts.user && !process.env.MANTA_USER)
usage('account is a required argument');
opts.host = option.optarg;
break;
case 'k':
opts.keyPath = option.optarg;
break;
case 'u':
opts.url = url.parse(option.optarg).href;
break;
case 'v':
// Allows us to set -vvv -> this little hackery
// just ensures that we're never < TRACE
LOG.level(Math.max(bunyan.TRACE, (LOG.level() - 10)));
if (LOG.level() <= bunyan.DEBUG)
LOG = LOG.child({src: true});
break;
default:
process.exit(1);
break;
}
}
if (!opts.url && !process.env.MANTA_URL)
usage('url is a required argument');
if (!opts.user && !process.env.MANTA_USER)
usage('account is a required argument');
global.OPBEAT_CLIENT.setExtraContext(_.assign({
level: OpbeatStream.levels[record.level],
}, _.omit(record, [ 'err', 'level', 'name', 'req', 'v' ])));
global.OPBEAT_CLIENT.captureError(record.err);
} else {
global.OPBEAT_CLIENT.setExtraContext(_.assign({
level: OpbeatStream.levels[record.level],
}, _.omit(record, [ 'level', 'name', 'v' ])));
}
}
}
OpbeatStream.levels = {
[bunyan.TRACE]: 'debug',
[bunyan.DEBUG]: 'debug',
[bunyan.INFO]: 'info',
[bunyan.WARN]: 'warning',
[bunyan.ERROR]: 'error',
[bunyan.FATAL]: 'fatal',
};
module.exports = bunyan.createLogger({
name: 'app-log',
streams: process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test' ? [
{ level: bunyan.TRACE, type: 'raw', stream: prettyStream },
] : [
{ level: bunyan.TRACE, type: 'raw', stream: new FileStream(path.join(loggerConfig.path, process.pid + '.log')) },
// { level: bunyan.TRACE, type: 'raw', stream: new OpbeatStream() },
],
serializers: _.defaults({
err (err) {
import { getLogPath } from './builder';
import { config } from './config';
export const ringbuffer = new bunyan.RingBuffer( { limit: 1000 } );
const dserveLogger = bunyan.createLogger( {
name: 'dserve',
streams: [
{
type: 'rotating-file',
path: './logs/log.txt',
period: '1d',
count: 7,
},
{
level: bunyan.DEBUG,
type: 'raw',
stream: ringbuffer,
},
{
stream: process.stdout,
level: bunyan.DEBUG,
},
],
serializers: bunyan.stdSerializers, // allows one to use err, req, and res as special keys
src: true,
} );
/* super convenient name */
export const l = {
log: dserveLogger.info.bind( dserveLogger ),
error: dserveLogger.error.bind( dserveLogger ),
import path from 'path';
import fs from 'fs-extra';
import { URL, URLSearchParams } from 'url';
import sanitizeFilename from 'sanitize-filename';
import axios from 'axios';
import bunyan from 'bunyan';
import { isString } from 'lodash';
import config from '../../config';
const log = bunyan.createLogger({
name: 'HttpService',
level: process.env.NODE_ENV === 'production' ? bunyan.INFO : bunyan.DEBUG,
});
/**
* Converts axios request configuration to equivalent valid filename.
*/
function getCacheFilePath(requestConfig) {
const { baseURL, url, params } = requestConfig;
// https://nodejs.org/docs/latest/api/url.html#url_url_strings_and_url_objects
const { hostname, pathname, searchParams, href } = new URL(url, baseURL);
// Merge params from config and search params from the URL
const keyValuePairs = new Set();
const addKeyValuePair = (value, key) => {
keyValuePairs.add(`${key}=${value}`);
};
// URLSearchParams are iterables, not arrays (so no map, filter, etc)
protected toBunyanLevel(logLevel: number): number {
switch (logLevel) {
case LogLevel.FATAL:
return bunyan.FATAL;
case LogLevel.ERROR:
return bunyan.ERROR;
case LogLevel.WARN:
return bunyan.WARN;
case LogLevel.INFO:
return bunyan.INFO;
case LogLevel.DEBUG:
return bunyan.DEBUG;
case LogLevel.TRACE:
return bunyan.TRACE;
default:
return bunyan.INFO;
}
}
function transformBunyanLevel(lvl) {
let newLvl = Math.min(bunyan.ERROR, Math.max(bunyan.DEBUG, lvl));
return (bunyan.nameFromLevel[newLvl] || "unknown").toUpperCase();
}
continue;
}
options = Object.assign({}, options, {
[`${prefix.repeat(i - 1)}${suffix}`]: current,
level
});
child = next.child(options, simple);
loggers[childName] = child;
}
if (debug.enabled(name)) {
child.level(bunyan.DEBUG);
}
return loggers[name];
};
constructor() {
this.log = bunyan.createLogger({
name: this.constructor.name,
level: process.env.NODE_ENV === 'production' ? bunyan.INFO : bunyan.DEBUG,
});
this.http = http;
this.db = db;
}