0.1.1 • Published 3 years ago
winston-transport-pg v0.1.1
winston-transport-pg
A PostgreSQL Transport for Winston Logger (v3.x).
Uses the node-postgres package, and does
not require native binding (libpq) to be installed on the host
machine.
Inspired by winston-pg-native.
Prerequisite
You must have a table that matches the following description:
CREATE TABLE logs (
timestamp TIMESTAMP WITH TIME ZONE DEFAULT now(),
level VARCHAR,
message VARCHAR,
meta JSON
);Installation
npm i winston-transport-pgUse
To create an instance of the PostgresTransport, we need two things:
- A
pgPool instance - An IPostgresTransportOptions object
IPostgresTransportOptions
Below is the interface for the IPostgresTransportOptions object.
interface IPostgresTransportOptions {
level?: string;
tableName: string;
}Creating an Instance
import { Pool } from 'pg';
import { createLogger, format } from 'winston';
// First create a Pool instance.
const pool = new Pool('postgres://username:password@hostname:5432/database');
// Set up our options.
const opts = {
level: 'info',
tableName: 'logs',
};
// Create the instance.
const postgresTransport = new PostgresTransport(pool, opts);
// Add Transport to Logger
const logger = createLogger({
format: format.json(),
transports: [ postgresTransport ]
});0.1.0
3 years ago
0.1.1
3 years ago
0.1.0-dev.3
5 years ago
0.1.0-dev.2
5 years ago
0.1.0-dev.1
5 years ago
0.1.0-dev.0
5 years ago