Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const ip = obj.req.headers['x-forwarded-for'] ||
obj.req.remoteAddress;
return console.log(`[${obj.time.toISOString()} - ${ip}]: ${obj.req.method} ${obj.req.url}`);
}
if (obj.level >= bunyan.WARN) {
if (obj.err) {
return console.log(`[${obj.time.toISOString()} - ${bunyan.nameFromLevel[obj.level].toUpperCase()}]: ${obj.err.name} ${obj.src.file}:${obj.src.line}
${obj.err.message}
${obj.err.stack}
${obj.msg}
`);
}
return console.log(`[${obj.time.toISOString()} - ${bunyan.nameFromLevel[obj.level].toUpperCase()}]: ${obj.msg} in ${obj.src.file}:${obj.src.line}`);
}
console.log(`[${obj.time.toISOString()} - ${bunyan.nameFromLevel[obj.level].toUpperCase()}]: ${obj.msg}`);
/* eslint-enable no-console */
};
} else if (data.level < bunyan.INFO) {
levelCss = 'color: GoldenRod';
} else if (data.level < bunyan.WARN) {
levelCss = 'color: DarkTurquoise';
} else if (data.level < bunyan.ERROR) {
levelCss = 'color: Purple';
} else if (data.level < bunyan.FATAL) {
levelCss = 'color: Crimson';
} else {
levelCss = 'color: Black';
}
console.log( // eslint-disable-line no-console
'[%s] %c%s%c: %s: %c%s',
data.time,
levelCss, bunyan.nameFromLevel[data.level],
defaultCss, loggerName,
msgCss, data.msg
);
if (data.err && data.err.stack) {
console.error(data.err.stack); // eslint-disable-line no-console
}
};
const rootLoggerOptions = {
name: DEFAULT_LOGGER_NAME,
streams: [{
type: 'raw',
name: 'ConsoleLogStream',
stream: new ConsoleLogStream({formatter: LogFormatter}),
level: 'info'
}],
level: 'info'
};
this.rootLogger = new Logger(rootLoggerOptions);
this._bindNodeLoggerMethods(this.rootLogger);
this._cleanLoggersInterval = null;
this.nameFromLevel = bunyan.nameFromLevel;
this.levelFromName = bunyan.levelFromName;
this.DEFAULT_LOGGER_NAME = DEFAULT_LOGGER_NAME;
// in case the node we're running has it's own logging system, we'll
// allow users to pass in callbacks for getting and setting loggers
// through the logging services (_handleGetLoggers, _handleSetLoggerLevel)
this._externalLog = {
getLoggers: null,
setLoggerLevel: null
};
KNOWN_LOGS.forEach((log) => {
this.generateLogger(log);
});
}
_getRosLogLevel(bunyanLogLevel) {
// ROS log levels defined in rosgraph_msgs/Log
// bunyan trace and debug levels will both map to ROS debug
if (bunyanLogLevel === bunyan.TRACE) {
return RosgraphLogMsg.Constants.DEBUG;
}
// else
return RosgraphLogMsg.Constants[bunyan.nameFromLevel[bunyanLogLevel].toUpperCase()];
}
write(rec) {
let name = bunyan.nameFromLevel[rec.level];
let method = (name === 'debug') ? 'log' : name;
console[method]('[%s]: %s', name, rec.msg); // eslint-disable-line
}
},
format(rec) {
return bunyan.nameFromLevel[rec.level].toUpperCase();
}
}
get: function () {
return bunyan.nameFromLevel[this.level()];
},
enumerable: true,
public get logLevelName(): string {
return bunyan.nameFromLevel[this.level()];
}
}
ClientLogentriesLogger.prototype.write = function (data = {}) {
const level = bunyan.nameFromLevel[data.level];
if (isFunction(LE[level])) {
LE[level](data);
} else {
LE.log(data);
}
};
this._forEachLogger((logger) => {
resp.loggers.push({
name: logger.getName(),
level: bunyan.nameFromLevel[logger.getLevel()]
});
}, true);