Skip to content

Commit

Permalink
Merge branch 'master' of github.com:winstonjs/winston
Browse files Browse the repository at this point in the history
  • Loading branch information
DABH committed Jul 10, 2024
2 parents a5853b5 + 93b52ac commit b56117e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 4,885 deletions.
78 changes: 78 additions & 0 deletions docs/transports.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ there are additional transports written by
* [Logsene](#logsene-transport) (including Log-Alerts and Anomaly Detection)
* [Logz.io](#logzio-transport)
* [Mail](#mail-transport)
* [MySQL](#mysql-transport)
* [New Relic](#new-relic-agent-transport)
* [Papertrail](#papertrail-transport)
* [Parseable](#parseable)
* [PostgresQL](#postgresql-transport)
* [Pusher](#pusher-transport)
* [Sentry](#sentry-transport)
Expand Down Expand Up @@ -641,6 +643,55 @@ The Mail transport uses [node-mail][17] behind the scenes. Options are the foll

*Metadata:* Stringified as JSON in email.

### MySQL Transport

[winston-mysql](https://github.com/charles-zh/winston-mysql) is a MySQL transport for Winston.

Create a table in your database first:

```sql
CREATE TABLE `sys_logs_default` (
`id` INT NOT NULL AUTO_INCREMENT,
`level` VARCHAR(16) NOT NULL,
`message` VARCHAR(2048) NOT NULL,
`meta` VARCHAR(2048) NOT NULL,
`timestamp` DATETIME NOT NULL,
PRIMARY KEY (`id`));
```

> 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.
Configure Winston with the transport:

```javascript
import MySQLTransport from 'winston-mysql';

const options = {
host: '${MYSQL_HOST}',
user: '${MYSQL_USER}',
password: '${MYSQL_PASSWORD}',
database: '${MYSQL_DATABASE}',
table: 'sys_logs_default'
};

const logger = winston.createLogger({
level: 'debug',
format: winston.format.json(),
defaultMeta: { service: 'user-service' },
transports: [
new winston.transports.Console({
format: winston.format.simple(),
}),
new MySQLTransport(options),
],
});

/// ...
let msg = 'My Log';
logger.info(msg, {message: msg, type: 'demo'});
```


### New Relic Agent Transport

[winston-newrelic-agent-transport][47] is a New Relic transport that leverages the New Relic agent:
Expand Down Expand Up @@ -682,6 +733,33 @@ The Papertrail transport connects to a [PapertrailApp log destination](https://p

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

### Parseable Transport

[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.

```js
// Using cjs
const { ParseableTransport } = require('parseable-winston')
const winston = require('winston')

const parseable = new ParseableTransport({
url: process.env.PARSEABLE_LOGS_URL, // Ex: 'https://parsable.myserver.local/api/v1/logstream'
username: process.env.PARSEABLE_LOGS_USERNAME,
password: process.env.PARSEABLE_LOGS_PASSWORD,
logstream: process.env.PARSEABLE_LOGS_LOGSTREAM, // The logstream name
tags: { tag1: 'tagValue' } // optional tags to be added with each ingestion
})

const logger = winston.createLogger({
levels: winston.config.syslog.levels,
transports: [parseable],
defaultMeta: { instance: 'app', hostname: 'app1' }
})

logger.info('User took the goggles', { userid: 1, user: { name: 'Rainier Wolfcastle' } })
logger.warning('The goggles do nothing', { userid: 1 })
```

### PostgresQL Transport

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

0 comments on commit b56117e

Please sign in to comment.