Skip to content

youmeb-lab/sima

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);

Push records into Elasticsearch

$ npm i --save es-writable

es-writable example

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

About

A super simple JSON logging library

Resources

Stars

Watchers

Forks

Packages

No packages published