winston-mysql-transport

A Mysql Transport for winston (http://www.github.com/flatiron/winston)

A Mysql transport for winston.

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

(or add it to your package.json)

First you must generate your log table

/*file : extras/schema.sql*/
CREATE TABLE IF NOT EXISTS `my_database`.`log_table` (
`id` int(10NOT NULL AUTO_INCREMENT,
`level` varchar(45) NOT NULL,
`message` text NOT NULL,
`timestamp` datetime NOT NULL,
`meta` varchar(255),
`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

This transport does not support (yet) :

  • streaming
  • querying
  • Saving of metadata