Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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');
});
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');
});
* robot.log.warn("Woah there");
* robot.log.error("ETOOMANYLOGS");
* robot.log.fatal("Goodbye, cruel world!");
*/
const Logger = require('bunyan')
const bunyanFormat = require('bunyan-format')
const serializers = require('./serializers')
// Return a function that defaults to "info" level, and has properties for
// other levels:
//
// robot.log("info")
// robot.log.trace("verbose details");
//
Logger.prototype.wrap = function () {
const fn = this.info.bind(this);
// Add level methods on the logger
['trace', 'debug', 'info', 'warn', 'error', 'fatal'].forEach(level => {
fn[level] = this[level].bind(this)
})
// Expose `child` method for creating new wrapped loggers
fn.child = (attrs) => {
// Bunyan doesn't allow you to overwrite name…
const name = attrs.name
delete attrs.name
const log = this.child(attrs, true)
// …Sorry, bunyan, doing it anwyway
if (name) log.fields.name = name
// eslint-disable-next-line @typescript-eslint/no-var-requires
const bunyan = require('bunyan');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const PrettyStream = require('bunyan-prettystream');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('../package.json');
const prettyStdOut = new PrettyStream();
prettyStdOut.pipe(process.stdout);
// TODO: replace bunyan with something that actually works with typescript
// Extend bunyan
bunyan.prototype.time = (action: string, startTime: number): void => {
let time = Date.now() - startTime;
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
this.info(
{
duration: time,
action: action,
type: 'TIMER',
},
`TIMER: ${action} completed in ${time} milliseconds`,
);
};
export type LogLevels = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
const Logger = new bunyan({
it('calls child on the logger bunyan instance', () => {
sinon.spy(bunyan.prototype, 'child');
log.child();
expect(bunyan.prototype.child).to.have.been.calledOnce;
});
it('instantiates a new logger with the new child', () => {
const stubChild = {};
sinon.stub(bunyan.prototype, 'child').returns(stubChild);
const child = log.child();
expect(child).not.to.eql(log);
expect(child._logger).to.eql(stubChild);
});
before(function () {
infoSpy = sinon.spy(bunyan.prototype, 'info');
});