Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for error instances #20

Merged
merged 2 commits into from Nov 15, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/jog.js
Expand Up @@ -99,6 +99,15 @@ Jog.prototype.write = function(level, type, attrs){
});
}

// check for Error
var err = attrs.error || attrs
if (err instanceof Error) {
attrs.error = {
stack: err.stack,
message: err.message
};
}

// add it to the store
this.store.add(attrs);
return this;
Expand Down Expand Up @@ -137,4 +146,4 @@ exports.levels.forEach(function(level){
Jog.prototype[level] = function(type, attrs){
this.write(level, type, attrs);
};
})
})
18 changes: 17 additions & 1 deletion test/jog.js
Expand Up @@ -30,6 +30,22 @@ describe('Jog', function(){
var log = new Jog(store);
log.info('something happened');
})

it('should handle error instances', function (done){
var err = new Error('BOOM')

var store = {
add: function(obj){
obj.error.stack.should.equal(err.stack);
obj.error.message.should.equal(err.message);
}
};

var log = new Jog(store);
log.error('something happened', { error: err });
log.error('even worse', err);
done();
})
})

describe('#ns(obj)', function(){
Expand All @@ -52,4 +68,4 @@ describe('Jog', function(){
log.info('something happened');
})
})
})
})