bunion
v0.2.137
Published
Semver-oriented TypeScript library skeleton.
Downloads
13
Maintainers
Readme
Bunion / BXN / B4N
This logging module is ~30% more performant than Bunyan when used as a part of a complete pipeline.
Advantages over other loggers like Bunyan
- Has a default logger, configured by
.bunion.js
- Uses array format instead of object format by default - more readable and more performant
- Has CLI tools for navigating log files
Basic API
- Only writes to stdout, not stderr
- Uses an array format by default:
return safe.stringify([ '@bunion:1', // the format of the logging line, with version number appName, // your app name level, // the logging level process.pid, // the process pid host, // the hostname where the log originated new Date().toUTCString(), // a UTC date string fields, // custom metadata - useful for filtering logs - fields is best used as an object {"xyz":"foo","filter":"on this"} message // your message, which is an array ]);
Installation
$ npm install bunion
| Usage
import log from 'bunion';
log.info('just saying hi.');
log.warn('shit hit the fan', 'part 2');
log.debug('boop', {yep:'this property is on an object'}, {'we can log': {'nested':["objects, also"]}});
the above will log this raw data to stdout:
["@bunion","foobar","INFO",10613,"host@you","Sun, 25 Aug 2019 23:05:42 GMT",null,["just saying hi."]]
["@bunion","foobar","WARN",10613,"host@you","Sun, 25 Aug 2019 23:05:42 GMT",null,["shit hit the fan","part 2"]]
["@bunion","foobar","DEBUG",10613,"host@you","Sun, 25 Aug 2019 23:05:42 GMT",null,["boop",{"yep":"this property is on an object"},{"we can log":{"nested":["objects, also"]}}]]
and then you can read/consume the logs via:
$ node foo.js | bunion
Use the following env value for higher performance:
$ bunion_max_level=warn node foo.js | bunion --level warn
Using the bunion config file to setup a default logger
Use
.bunion.js
in the root of your project or current working directory.
const getDefaultBunionConf = (): BunionConf => {
return {
producer: {
name: 'default',
appName: 'default',
forceRaw: false,
level: 'TRACE',
fields: {}
},
consumer: {
localeDateString: 'en-US',
highlightMatches: true,
level: 'TRACE',
match: [],
matchAny: [],
matchAll: [],
inspect: {
array: {
length: 25
},
object: {
depth: 5
}
},
transform: {
keys: {}
}
}
}
};
How it works:
Something like this:
echo '{"@bunion":true,"level":"WARN","appName":"my-api","date":"08-22-1984","value":"this is the end"}' | bunion
Will display this in your terminal:
08-22-1984 app:my-api WARN this is the end
Something like this:
echo '["@bunion","app","INFO",333,"host","date-str",null,"message1"]' | bunion
Will display this in your terminal:
date-str app:app INFO message1
Something like this:
echo '["@bunion","app","INFO",333,"host","date-str",null,["message1","message2",{"foo":"bar"}]]' | bunion
Will display this in your terminal:
date-str app:app INFO message1 message2 {
foo: 'bar'
}