Universal winston SQL transport.
Supports:
- MySQL
- PostgreSQL
- SQL Server
via knex library.
$ 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.
See the default values used:
const options = {
tableName: 'winston_logs',
};
const { Logger } = require('winston');
const { SQLTransport } = require('./../lib/winston-sql-transport');
const logger = new Logger({
transports: [
new SQLTransport({
tableName: 'winston_logs',
})]
});
module.exports = logger;
logger.log('info', 'message', {});
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 allows you to stream your logs back
//
// Start at the end.
//
logger.stream({ start: -1 }).on('log', (log) => {
console.log(log);
});
The tests are written in vows, and designed to be run with npm.
$ npm test