Skip to content

Latest commit

 

History

History
107 lines (78 loc) · 2.32 KB

README.md

File metadata and controls

107 lines (78 loc) · 2.32 KB

winston-sql-transport

CircleCI NPM version Dependency Status NPM Downloads

Universal winston SQL transport.

Supports:

  • MySQL
  • PostgreSQL
  • SQL Server

via knex library.

Installation

  $ npm install winston
  $ npm install winston-sql-transport

and then install the appropriate database library: pg for PostgreSQL, mysql for MySQL or MariaDB or mssql for MSSQL.

Options

See the default values used:

const options = {
  tableName: 'winston_logs',
};

Usage

const { Logger } = require('winston');
const { SQLTransport } = require('./../lib/winston-sql-transport');

const logger = new Logger({
  transports: [
    new SQLTransport({
      tableName: 'winston_logs',
    })]
});

module.exports = logger;

Logging

logger.log('info', 'message', {});

Querying Logs

This transport supports querying of logs with Loggly-like options. See Loggly Search API

const options = {
  fields: ['message'],
  from: new Date - 24 * 60 * 60 * 1000,
  until: new Date,
  start: 0,
  limit: 10,
  order: 'desc'
};

//
// Find items logged between today and yesterday.
//
logger.query(options, (err, results) => {
  if (err) {
    throw err;
  }

  console.log(results);
});

Streaming Logs

Streaming allows you to stream your logs back

//
// Start at the end.
//
logger.stream({ start: -1 }).on('log', (log) => {
  console.log(log);
});

Run Tests

The tests are written in vows, and designed to be run with npm.

  $ npm test

LICENSE

MIT License