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',
appName,
level,
process.pid,
host,
new Date().toUTCString(),
fields,
message
]);
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.
Default logger configuration
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:
Example 1
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
Example 2
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
Example 3
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'
}