Skip to content

1mike12/winston-bookshelfjs-transport

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A bookshelfjs transport for winston.

Installation

  $ npm install bookshelf
  $ npm install knex
  $ npm install winston
  $ npm install winston-bookshelfjs-transport

Preparation

First you must generate your log table migration

var TABLE_NAME = "logs";
exports.up = function(knex, Promise) {
    return knex.schema.createTableIfNotExists(TABLE_NAME, function (table){
        table.increments();
        table.string("level");
        table.string("message");
        table.string("meta");

        table.timestamps();
        table.dateTime("deleted_at");
    });
};

exports.down = function(knex, Promise) {
    return knex.schema.dropTableIfExists(TABLE_NAME)
};

Then make your log model

var bookshelf = require('./your-bookshelf-file');
var tableName = "logs";

var instanceMembers = function(){
    var self = this;
    self.tableName = tableName;
};

var staticMembers = function(){
    var self = this;

    self.tableName = tableName;
    self.requiredColumns = [];
};

module.exports = bookshelf.Model.extend(new instanceMembers, new staticMembers);

Usage

make sure that you are passing in your bookshelf Log model into the options.

var winston = require('winston');

// Requiring `winston-bookshelf-transport` will expose `winston.transports.Bookshelf`
require('./modules/log/winston-bookshelf-transport').BookshelfTransport;

options = {
    model: require("./models/Log")
};

var logger = new (winston.Logger)();
logger.add(winston.transports.BookshelfTransport, options);
logger.info("test");

Attribution

Lifted some code from sapher's mysql-wisnton-transport

About

A winston transport for use with bookshelfjs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published