Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('bunyan-request-logger', function () {
var infoSpy;
var errorSpy;
var app = createDefaultApp({level: bunyan.FATAL});
before(function () {
infoSpy = sinon.spy(bunyan.prototype, 'info');
errorSpy = sinon.spy(bunyan.prototype, 'error');
// hide console errors while running the tests
sinon.stub(console, 'error');
});
beforeEach(function () {
infoSpy.reset();
errorSpy.reset();
});
after(function () {
infoSpy.restore();
describe('bunyan-request-logger log.gif', function () {
var infoSpy;
var app = createDefaultApp({level: bunyan.FATAL});
before(function () {
infoSpy = sinon.spy(bunyan.prototype, 'info');
});
beforeEach(function () {
infoSpy.reset();
});
after(function () {
infoSpy.restore();
});
describe('logging', function () {
it('should log the request id in the response at the info level', function (done) {
expect(outputCapture.get().level).to.equal(bunyan.INFO);
reset();
rosnodejs.log.warn(message);
expect(outputCapture.get().msg).to.have.string(message);
expect(outputCapture.get().level).to.equal(bunyan.WARN);
reset();
rosnodejs.log.error(message);
expect(outputCapture.get().msg).to.have.string(message);
expect(outputCapture.get().level).to.equal(bunyan.ERROR);
reset();
rosnodejs.log.fatal(message);
expect(outputCapture.get().msg).to.have.string(message);
expect(outputCapture.get().level).to.equal(bunyan.FATAL);
reset();
rosnodejs.log.traceThrottle(1, message);
expect(outputCapture.get().msg).to.have.string(message);
expect(outputCapture.get().level).to.equal(bunyan.TRACE);
reset();
rosnodejs.log.debugThrottle(1, message);
expect(outputCapture.get().msg).to.have.string(message);
expect(outputCapture.get().level).to.equal(bunyan.DEBUG);
reset();
rosnodejs.log.infoThrottle(1, message);
expect(outputCapture.get().msg).to.have.string(message);
expect(outputCapture.get().level).to.equal(bunyan.INFO);
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;
}
}
response = "Debug";
break;
}
case bunyan.INFO: {
response = "Information";
break;
}
case bunyan.WARN: {
response = "Warning";
break;
}
case bunyan.ERROR: {
response = "Error";
break;
}
case bunyan.FATAL: {
response = "Fatal";
break;
}
default: {
response = "Information";
}
}
return response;
}
BunyanPrettyPrinter.prototype._transform = function (chunk, _, callback)
{
var component = chunk.component || chunk.name;
var message = chunk.msg;
var stream = this;
var level;
switch (chunk.level) {
case mod_bunyan.TRACE: level = 'TRACE'; break;
case mod_bunyan.DEBUG: level = 'DEBUG'; break;
case mod_bunyan.INFO: level = 'INFO'; break;
case mod_bunyan.WARN: level = 'WARN'; break;
case mod_bunyan.ERROR: level = 'ERROR'; break;
case mod_bunyan.FATAL: level = 'FATAL'; break;
default: level = '?????'; break;
}
this.push(sprintf('[%5s] %s: %s\n', level, component, message));
mod_jsprim.forEachKey(chunk, function (key, value) {
if (bunyanStdKeys.hasOwnProperty(key))
return;
stream.push(sprintf(' %10s: %j\n', key, value));
});
callback();
};
private static levelSerialiser(level) {
switch (level) {
case bunyan.TRACE:
return 'TRACE';
case bunyan.DEBUG:
return 'DEBUG';
case bunyan.INFO:
return 'INFO';
case bunyan.WARN:
return 'WARN';
case bunyan.ERROR:
return 'ERROR';
case bunyan.FATAL:
return 'FATAL';
default:
return 'N/A';
}
}
protected toTheiaLevel(bunyanLogLevel: number | string): number {
switch (Number(bunyanLogLevel)) {
case bunyan.FATAL:
return LogLevel.FATAL;
case bunyan.ERROR:
return LogLevel.ERROR;
case bunyan.WARN:
return LogLevel.WARN;
case bunyan.INFO:
return LogLevel.INFO;
case bunyan.DEBUG:
return LogLevel.DEBUG;
case bunyan.TRACE:
return LogLevel.TRACE;
default:
return LogLevel.INFO;
}
}
mockedBunyan.createLogger = ({ level, ...otherConfig }) => bunyan.createLogger({
...otherConfig,
level: bunyan.FATAL,
});