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');
$ npm i --save sima
$ npm i -g sima # command line tool
sima.info('type %s', 'something');
sima.error('...');
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']);
We can't pipe
sima to process.stdout
, because sima outputs Object
s not String
s:
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);
$ npm i --save es-writable
$ cat sima.log | sima
$ cat sima.log | sima --format '[{{time}}] {{upperName}} {{app}}: {{!msg}}'
$ cat sima.log | sima --filter '/hello/.test(data.msg)'