Skip to content

Commit b56117e

Browse files
committed
Merge branch 'master' of github.com:winstonjs/winston
2 parents a5853b5 + 93b52ac commit b56117e

File tree

4 files changed

+83
-4885
lines changed

4 files changed

+83
-4885
lines changed

docs/transports.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ 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)
54+
* [Parseable](#parseable)
5355
* [PostgresQL](#postgresql-transport)
5456
* [Pusher](#pusher-transport)
5557
* [Sentry](#sentry-transport)
@@ -641,6 +643,55 @@ The Mail transport uses [node-mail][17] behind the scenes. Options are the foll
641643

642644
*Metadata:* Stringified as JSON in email.
643645

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+
CREATE TABLE `sys_logs_default` (
654+
`id` INT NOT 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+
import MySQLTransport from 'winston-mysql';
668+
669+
const options = {
670+
host: '${MYSQL_HOST}',
671+
user: '${MYSQL_USER}',
672+
password: '${MYSQL_PASSWORD}',
673+
database: '${MYSQL_DATABASE}',
674+
table: 'sys_logs_default'
675+
};
676+
677+
const logger = winston.createLogger({
678+
level: 'debug',
679+
format: winston.format.json(),
680+
defaultMeta: { service: 'user-service' },
681+
transports: [
682+
new winston.transports.Console({
683+
format: winston.format.simple(),
684+
}),
685+
new MySQLTransport(options),
686+
],
687+
});
688+
689+
/// ...
690+
let msg = 'My Log';
691+
logger.info(msg, {message: msg, type: 'demo'});
692+
```
693+
694+
644695
### New Relic Agent Transport
645696

646697
[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
682733

683734
*Metadata:* Logged as a native JSON object to the 'meta' attribute of the item.
684735

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.
739+
740+
```js
741+
// Using cjs
742+
const { ParseableTransport } = require('parseable-winston')
743+
const winston = require('winston')
744+
745+
const parseable = new ParseableTransport({
746+
url: process.env.PARSEABLE_LOGS_URL, // Ex: 'https://parsable.myserver.local/api/v1/logstream'
747+
username: process.env.PARSEABLE_LOGS_USERNAME,
748+
password: process.env.PARSEABLE_LOGS_PASSWORD,
749+
logstream: process.env.PARSEABLE_LOGS_LOGSTREAM, // The logstream name
750+
tags: { tag1: 'tagValue' } // optional tags to be added with each ingestion
751+
})
752+
753+
const logger = winston.createLogger({
754+
levels: winston.config.syslog.levels,
755+
transports: [parseable],
756+
defaultMeta: { instance: 'app', hostname: 'app1' }
757+
})
758+
759+
logger.info('User took the goggles', { userid: 1, user: { name: 'Rainier Wolfcastle' } })
760+
logger.warning('The goggles do nothing', { userid: 1 })
761+
```
762+
685763
### PostgresQL Transport
686764

687765
[@pauleliet/winston-pg-native](https://github.com/petpano/winston-pg-native) is a PostgresQL transport supporting Winston 3.X.

0 commit comments

Comments
 (0)