A Mysql Transport for winston (http://www.github.com/flatiron/winston)
JavaScript
Pull request Compare This branch is 3 commits ahead of nvdnkpr:master.
Latest commit 2e413b4 Dec 30, 2013 @pepoviola change type in readme
Failed to load latest commit information.
extras change field type to text Dec 30, 2013
lib add meta_stack field to log the stack trace Dec 4, 2013
test Initial commit Sep 17, 2013
.gitignore Initial commit Sep 17, 2013
LICENSE Initial commit Sep 17, 2013
README.md change type in readme Dec 30, 2013
package.json Initial commit Sep 17, 2013

README.md

A Mysql transport for winston.

Installation

Installing winston-mysql-transport via npm

  $ npm install winston
  $ npm install winston-mysql-transport

(or add it to your package.json)

Usage

First you must generate your log table

/*file : extras/schema.sql*/
CREATE TABLE IF NOT EXISTS `my_database`.`log_table` (
    `id` int(10) NOT NULL AUTO_INCREMENT,
    `level` varchar(45) NOT NULL,
    `message` text NOT NULL,
    `timestamp` datetime NOT NULL,
    `meta` varchar(255),
  `meta_stack` text NOT NULL,
    `hostname` varchar(255),
    PRIMARY KEY (`id`)
);

And in your code...

  var winston = require('winston');

  //
  // Requiring `winston-mysql-transport` will expose
  // `winston.transports.Mysql`
  //
  require('winston-mysql-transport').Mysql;

  options = {
    database : "my_database",
    table : "log_table",
    user : "root"
  }

  winston.add(winston.transports.Mysql, options);

You can find a list of options that you can pass here :

https://github.com/felixge/node-mysql#connection-options

Unsupported

This transport does not support (yet) :

  • streaming
  • querying
  • Saving of metadata (implement stack saving only)