Skip to content

Commit

Permalink
Changed .msg -> .type
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Apr 10, 2012
1 parent b2a2348 commit 240d053
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
28 changes: 14 additions & 14 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@

## API

### log.write(level, msg[, obj])
### log.write(level, type[, obj])

Write to the logs:

```js
log.write(level, msg[, obj])
log.debug(msg[, obj])
log.info(msg[, obj])
log.warn(msg[, obj])
log.error(msg[, obj])
log.write(level, type[, obj])
log.debug(type[, obj])
log.info(type[, obj])
log.warn(type[, obj])
log.error(type[, obj])
```

### log.ns(obj)
Expand Down Expand Up @@ -66,7 +66,7 @@ log = log.ns({ uid: 5, vid: 99 });

Log random data using the `FileStore` and tail the file
for changes (typically in different processes). Jog will add
the `.level` and `.msg` properties for you.
the `.level` and `.type` properties for you.

```js
var jog = require('jog')
Expand All @@ -93,11 +93,11 @@ yields:
```js
{ id: 1,
level: 'info',
msg: 'something happened',
type: 'something happened',
timestamp: 1332907641734 }
{ id: 2,
level: 'info',
msg: 'something happened',
type: 'something happened',
timestamp: 1332907641771 }
...
```
Expand Down Expand Up @@ -130,12 +130,12 @@ jog --file /tmp/jog --select "_.user == 'tobi'"
[ { user: 'tobi',
duration: 1000,
level: 'info',
msg: 'rendering video',
type: 'rendering video',
timestamp: 1332861272100 },
{ user: 'tobi',
duration: 2000,
level: 'info',
msg: 'compiling video',
type: 'compiling video',
timestamp: 1332861272100 },
...
```
Expand All @@ -150,7 +150,7 @@ $ jog --file /var/log/videos.log --select "_.user == 'tobi'" --map _.duration
Flags can be used several times:

```
jog --file /var/log/videos.log --select "_.vid < 5" --map _.msg --map "_.split(' ')"
jog --file /var/log/videos.log --select "_.vid < 5" --map _.type --map "_.split(' ')"
[ [ 'compiling', 'video' ],
[ 'compiling', 'video' ],
[ 'compiling', 'video' ],
Expand All @@ -162,14 +162,14 @@ jog --file /var/log/videos.log --select "_.vid < 5" --map _.msg --map "_.split('
```
$ jog --file my.log -f -c --select '_.level == "error"'
{ level: 'error',
msg: 'something broke',
type: 'something broke',
timestamp: 1333943982669 }
```

Display error messages within the last 10 seconds:

```
$ jog -F my.log --level error --select "Date.now() - _.timestamp < 10000" --map _.msg
$ jog -F my.log --level error --select "Date.now() - _.timestamp < 10000" --map _.type
[ 'something broke', 'something broke', 'something broke' ]
```

Expand Down
12 changes: 6 additions & 6 deletions lib/jog.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@ Jog.prototype.ns = function(obj){
};

/**
* Write the given log `level`, `msg`, and `attrs` object
* Write the given log `level`, `type`, and `attrs` object
* to the store.
*
* @param {String} level
* @param {String} msg
* @param {String} type
* @param {Object} attrs
* @api public
*/

Jog.prototype.write = function(level, msg, attrs){
Jog.prototype.write = function(level, type, attrs){
var defaults = this.defaults;
attrs = attrs || {};
attrs.level = level;
attrs.msg = msg;
attrs.type = type;

// implicit timestamp
attrs.timestamp = attrs.timestamp || Date.now();
Expand Down Expand Up @@ -140,7 +140,7 @@ Jog.prototype.clear = function(fn){
*/

exports.levels.forEach(function(level){
Jog.prototype[level] = function(msg, attrs){
this.write(level, msg, attrs);
Jog.prototype[level] = function(type, attrs){
this.write(level, type, attrs);
};
})
6 changes: 3 additions & 3 deletions test/jog.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ describe('Jog', function(){
})
})

describe('#write(level, msg, attrs)', function(){
describe('#write(level, type, attrs)', function(){
it('should .add() to the store', function(done){
var store = {
add: function(obj){
obj.level.should.equal('info');
obj.timestamp.should.be.a('number');
obj.msg.should.equal('something happened');
obj.type.should.equal('something happened');
done();
}
};
Expand All @@ -44,7 +44,7 @@ describe('Jog', function(){
obj.uid.should.equal('tobi');
obj.level.should.equal('info');
obj.timestamp.should.be.a('number');
obj.msg.should.equal('something happened');
obj.type.should.equal('something happened');
done();
}
};
Expand Down
4 changes: 2 additions & 2 deletions test/shared/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module.exports = function(store){
lines[0].should.have.property('timestamp');
delete lines[0].timestamp;
delete lines[1].timestamp;
lines[0].should.eql({ vid: 'abc', level: 'info', msg: 'compiling video' });
lines[1].should.eql({ vid: 'abc', level: 'info', msg: 'uploading video' });
lines[0].should.eql({ vid: 'abc', level: 'info', type: 'compiling video' });
lines[1].should.eql({ vid: 'abc', level: 'info', type: 'uploading video' });
done();
});
})
Expand Down

0 comments on commit 240d053

Please sign in to comment.