2.0.0 • Published 9 years ago

sima v2.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

Sima

Sima is a super simple JSON logging library. if you are enjoying with Stream, you will love it.

var sima = Sima('myapp')
  .useDefaultLevels();
  
sima.level('info')
  .pipe(Sima.stringify())
  .pipe(process.stdout);

sima.info('type %s', 'somethings');

Sima Guang

Installation

$ npm i --save sima
$ npm i -g sima # command line tool

How to write data to Sima?

Basic

sima.info('type %s', 'something');
sima.error('...');

As a stream

Sima is a PassThrough stream, so you can use write method directly or pipe other Readable stream to Sima, for example:

sima.write(['info', 'message']);
sima.write(['info', 'message'], callback);
sima.write(['info', '%s', 'message']);
sima.write(['info', '%s', 'message'], callback);

duplex.pipe(sima);
duplex.write(['info', 'message']);

How to output data to console/file?

We can't pipe sima to process.stdout, because sima outputs Objects not Strings:

sima.pipe(process.stdout);

Therefore, we need to convert Object to String:

// json string
sima
  .pipe(Sima.stringify())
  .pipe(process.stdout);

// pretty print 
sima
  .pipe(Sima.prettify({
     // this is optinal
     // syntax: https://github.com/visionmedia/minstache
     format: '[{{time}}] {{upperName}} {{app}}: {{!msg}}'
   }))
  .pipe(process.stdout);

CLI Usage

Pretty Print

$ cat sima.log | sima
$ cat sima.log | sima --format '[{{time}}] {{upperName}} {{app}}: {{!msg}}'

Filter/Search

$ cat sima.log | sima --filter '/hello/.test(data.msg)'

Examples

./examples

License

MIT: http://poying.mit-license.org