Permalink
Browse files

Check for error instances

  • Loading branch information...
1 parent e42e734 commit d7bb299c30c636f7a9b3f6ad289924fbb59a1412 @danmilon danmilon committed Nov 14, 2012
Showing with 22 additions and 2 deletions.
  1. +6 −1 lib/jog.js
  2. +16 −1 test/jog.js
View
@@ -99,6 +99,11 @@ Jog.prototype.write = function(level, type, attrs){
});
}
+ // check for Error
+ if (attrs.error instanceof Error) {
+ attrs.error = attrs.error.stack || attrs.error.message;
+ }
+
// add it to the store
this.store.add(attrs);
return this;
@@ -137,4 +142,4 @@ exports.levels.forEach(function(level){
Jog.prototype[level] = function(type, attrs){
this.write(level, type, attrs);
};
-})
+})
View
@@ -30,6 +30,21 @@ 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.should.equal(err.stack);
+ obj.x.should.equal('y');
+ done();
+ }
+ };
+
+ var log = new Jog(store);
+ log.error('something happened', { error: err, x: 'y' });
+ })
})
describe('#ns(obj)', function(){
@@ -52,4 +67,4 @@ describe('Jog', function(){
log.info('something happened');
})
})
-})
+})

0 comments on commit d7bb299

Please sign in to comment.