@@ -48,6 +48,7 @@ there are additional transports written by
4848  *  [ Logsene] ( #logsene-transport )  (including Log-Alerts and Anomaly Detection)
4949  *  [ Logz.io] ( #logzio-transport ) 
5050  *  [ Mail] ( #mail-transport ) 
51+   *  [ MySQL] ( #mysql-transport ) 
5152  *  [ New Relic] ( #new-relic-agent-transport ) 
5253  *  [ Papertrail] ( #papertrail-transport ) 
5354  *  [ PostgresQL] ( #postgresql-transport ) 
@@ -641,6 +642,55 @@ The Mail transport uses [node-mail][17] behind the scenes.  Options are the foll
641642
642643* Metadata:*  Stringified as JSON in email.
643644
645+ ### MySQL Transport  
646+ 
647+ [ winston-mysql] ( https://github.com/charles-zh/winston-mysql )  is a MySQL transport for Winston.
648+ 
649+ Create a table in your database first:
650+ 
651+ ``` sql 
652+  CREATE  TABLE  `sys_logs_default ` (
653+  ` id` INT  NOT NULL  AUTO_INCREMENT,
654+  ` level` VARCHAR (16 ) NOT NULL ,
655+  ` message` VARCHAR (2048 ) NOT NULL ,
656+  ` meta` VARCHAR (2048 ) NOT NULL ,
657+  ` timestamp` NOT NULL ,
658+  PRIMARY KEY  (` id` 
659+ ``` 
660+ 
661+ >  You can also specify ` meta `  to be a ` JSON `  field on MySQL 5.7+, i.e., ``meta`  JSON NOT NULL ` , which is helfpul for searching and parsing.
662+ 
663+ Configure Winston with the transport:
664+ 
665+ ``` javascript 
666+ import  MySQLTransport  from  ' winston-mysql' 
667+ 
668+ const  options  =  {
669+     host:  ' ${MYSQL_HOST}' 
670+     user:  ' ${MYSQL_USER}' 
671+     password:  ' ${MYSQL_PASSWORD}' 
672+     database:  ' ${MYSQL_DATABASE}' 
673+     table:  ' sys_logs_default' 
674+ };
675+ 
676+ const  logger  =  winston .createLogger ({
677+     level:  ' debug' 
678+     format:  winston .format .json (),
679+     defaultMeta:  { service:  ' user-service' 
680+     transports:  [
681+         new  winston.transports.Console ({
682+             format:  winston .format .simple (),
683+         }),
684+         new  MySQLTransport (options),
685+     ],
686+ });
687+ 
688+ // / ...
689+ let  msg =  ' My Log' 
690+ logger .info (msg, {message:  msg, type:  ' demo' 
691+ ``` 
692+ 
693+ 
644694### New Relic Agent Transport  
645695
646696[ winston-newrelic-agent-transport] [ 47 ]  is a New Relic transport that leverages the New Relic agent:
0 commit comments