sima
v2.0.0
Published
A super simple JSON logging library
Downloads
10
Readme
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');
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 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);
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)'