You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/transports.md
+78Lines changed: 78 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -48,8 +48,10 @@ there are additional transports written by
48
48
*[Logsene](#logsene-transport) (including Log-Alerts and Anomaly Detection)
49
49
*[Logz.io](#logzio-transport)
50
50
*[Mail](#mail-transport)
51
+
*[MySQL](#mysql-transport)
51
52
*[New Relic](#new-relic-agent-transport)
52
53
*[Papertrail](#papertrail-transport)
54
+
*[Parseable](#parseable)
53
55
*[PostgresQL](#postgresql-transport)
54
56
*[Pusher](#pusher-transport)
55
57
*[Sentry](#sentry-transport)
@@ -641,6 +643,55 @@ The Mail transport uses [node-mail][17] behind the scenes. Options are the foll
641
643
642
644
*Metadata:* Stringified as JSON in email.
643
645
646
+
### MySQL Transport
647
+
648
+
[winston-mysql](https://github.com/charles-zh/winston-mysql) is a MySQL transport for Winston.
649
+
650
+
Create a table in your database first:
651
+
652
+
```sql
653
+
CREATETABLE `sys_logs_default` (
654
+
`id`INTNOT NULL AUTO_INCREMENT,
655
+
`level`VARCHAR(16) NOT NULL,
656
+
`message`VARCHAR(2048) NOT NULL,
657
+
`meta`VARCHAR(2048) NOT NULL,
658
+
`timestamp` DATETIME NOT NULL,
659
+
PRIMARY KEY (`id`));
660
+
```
661
+
662
+
> 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.
663
+
664
+
Configure Winston with the transport:
665
+
666
+
```javascript
667
+
importMySQLTransportfrom'winston-mysql';
668
+
669
+
constoptions= {
670
+
host:'${MYSQL_HOST}',
671
+
user:'${MYSQL_USER}',
672
+
password:'${MYSQL_PASSWORD}',
673
+
database:'${MYSQL_DATABASE}',
674
+
table:'sys_logs_default'
675
+
};
676
+
677
+
constlogger=winston.createLogger({
678
+
level:'debug',
679
+
format:winston.format.json(),
680
+
defaultMeta: { service:'user-service' },
681
+
transports: [
682
+
newwinston.transports.Console({
683
+
format:winston.format.simple(),
684
+
}),
685
+
newMySQLTransport(options),
686
+
],
687
+
});
688
+
689
+
/// ...
690
+
let msg ='My Log';
691
+
logger.info(msg, {message: msg, type:'demo'});
692
+
```
693
+
694
+
644
695
### New Relic Agent Transport
645
696
646
697
[winston-newrelic-agent-transport][47] is a New Relic transport that leverages the New Relic agent:
@@ -682,6 +733,33 @@ The Papertrail transport connects to a [PapertrailApp log destination](https://p
682
733
683
734
*Metadata:* Logged as a native JSON object to the 'meta' attribute of the item.
684
735
736
+
### Parseable Transport
737
+
738
+
[Parseable](https://parseable.com/) is an open source, general purpose log analytics system. [Parseable-Winston](https://github.com/jybleau/parseable-node-loggers/tree/main/packages/winston#parseable-winston) is a Parseable transport for Winston.
0 commit comments