https://github.com/oresoftware/bunion
Bunyan's weird cousin. Has foot issues.
https://github.com/oresoftware/bunion
json logging logs nodejs pipeline pipelines
Last synced: 24 days ago
JSON representation
Bunyan's weird cousin. Has foot issues.
- Host: GitHub
- URL: https://github.com/oresoftware/bunion
- Owner: ORESoftware
- License: mit
- Created: 2018-04-25T01:10:09.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-04-17T22:35:18.000Z (almost 2 years ago)
- Last Synced: 2024-10-12T08:48:02.482Z (over 1 year ago)
- Topics: json, logging, logs, nodejs, pipeline, pipelines
- Language: TypeScript
- Homepage:
- Size: 332 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 33
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README

[](https://www.npmjs.com/package/bunion)
----
# 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
> 1. Has a default logger, configured by `.bunion.js`
> 2. Uses array format instead of object format by default - more readable and more performant
> 3. Has CLI tools for navigating log files
> Basic API
> 1. Only writes to stdout, not stderr
> 2. Uses an array format by default:
>
>```typescript
> 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
```bash
$ npm install bunion
```
## | Usage
```typescript
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:
```console
["@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:
```bash
$ node foo.js | bunion
```
Use the following env value for higher performance:
```bash
$ 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
```typescript
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:
```bash
echo '{"@bunion":true,"level":"WARN","appName":"my-api","date":"08-22-1984","value":"this is the end"}' | bunion
```
Will display this in your terminal:
```console
08-22-1984 app:my-api WARN this is the end
```
----
Example 2
Something like this:
```bash
echo '["@bunion","app","INFO",333,"host","date-str",null,"message1"]' | bunion
```
Will display this in your terminal:
```console
date-str app:app INFO message1
```
-----
Example 3
Something like this:
```bash
echo '["@bunion","app","INFO",333,"host","date-str",null,["message1","message2",{"foo":"bar"}]]' | bunion
```
Will display this in your terminal:
```console
date-str app:app INFO message1 message2 {
foo: 'bar'
}
```