Store your Bunyan logs in PostgreSQL.
This module creates a Bunyan stream that maps the default log fields to table columns and also records the entire log message in a jsonb
column to support your custom fields.
Requires PostgreSQL 9.4 or above for use with JSONB column types.
$ npm install --save bunyan-postgres-stream
First, create the table you want to store your logs in:
create table if not exists "public"."logs" (
"id" serial primary key,
"name" text,
"level" integer,
"hostname" text,
"msg" text,
"pid" integer,
"time" timestamptz,
"content" jsonb
)
Then, use the package as a Bunyan stream:
const bunyan = require('bunyan');
const bunyanPostgresStream = require('./');
const stream = bunyanPostgresStream({
connection: {
host: 'localhost',
user: 'postgres',
password: 'password',
database: 'db'
},
tableName: 'logs'
});
const log = bunyan.createLogger({
name: 'postgres stream',
level: 'info',
stream
});
log.info('something happened');
stream.end();
Type: object
One of the following:
- a valid node-postgres connection options object
- an initialized knex.js instance (see examples/knex.js)
Type: string
The name of the table that will contain the logs.
Pull requests welcome.
MIT © Forrest Desjardins