In winston
a transport is essentially a storage device for your logs. Each instance of a winston logger can have multiple transports configured at different levels. For example, one may want error logs to be stored in a persistent remote location (like a database), but all logs output to the console or a local file.
There are several core transports included in winston
, which leverage the built-in networking and file I/O offered by node.js core. In addition, there are third-party transports which are supported by the winston core team. And last (but not least) there are additional transports written by members of the community.
There are several core transports included in winston
, which leverage the built-in networking and file I/O offered by node.js core.
winston.add(winston.transports.Console, options)
The Console transport takes two simple options:
Metadata: Logged via util.inspect(meta);
winston.add(winston.transports.File, options)
The File transport should really be the 'Stream' transport since it will accept any WritableStream. It is named such because it will also accept filenames via the 'filename' option:
Metadata: Logged via util.inspect(meta);
winston.add(winston.transports.Http, options)
The Http
transport is a generic way to log, query, and stream logs from an arbitrary Http endpoint, preferably winstond. It takes options that are passed to the node.js http
or https
request:
username
and password
for HTTP Basic AuthStarting with winston@0.3.0
an effort was made to remove any transport which added additional dependencies to winston
. At the time there were several transports already in winston
which will always be supported by the winston core team.
As of winston@0.6.0
the CouchDB transport has been broken out into a new module: winston-couchdb.
winston.add(winston.transports.Couchdb, options)
The Couchdb
will place your logs in a remote CouchDB database. It will also create a Design Document, _design/Logs
for later querying and streaming your logs from CouchDB. The transport takes the following options:
username
and password
for HTTP Basic Auth winston.add(winston.transports.Redis, options)
This transport accepts the options accepted by the node-redis client:
In addition to these, the Redis transport also accepts the following options.
Metadata: Logged as JSON literal in Redis
As of winston@0.6.0
the Loggly transport has been broken out into a new module: winston-loggly.
winston.add(winston.transports.Loggly, options);
The Loggly transport is based on Nodejitsu's node-loggly implementation of the Loggly API. If you haven't heard of Loggly before, you should probably read their value proposition. The Loggly transport takes the following options. Either 'inputToken' or 'inputName' is required:
Metadata: Logged in suggested Loggly format
As of winston@0.3.0
the Riak transport has been broken out into a new module: winston-riak. Using it is just as easy:
var Riak = require('winston-riak').Riak; winston.add(Riak, options);
In addition to the options accepted by the riak-js client, the Riak transport also accepts the following options. It is worth noting that the riak-js debug option is set to false by default:
// Use a single bucket for all your logs var singleBucketTransport = new (Riak)({ bucket: 'some-logs-go-here' }); // Generate a dynamic bucket based on the date and level var dynamicBucketTransport = new (Riak)({ bucket: function (level, msg, meta, now) { var d = new Date(now); return level + [d.getDate(), d.getMonth(), d.getFullYear()].join('-'); } });
Metadata: Logged as JSON literal in Riak
As of winston@0.3.0
the MongoDB transport has been broken out into a new module: winston-mongodb. Using it is just as easy:
var MongoDB = require('winston-mongodb').MongoDB; winston.add(MongoDB, options);
The MongoDB transport takes the following options. 'db' is required:
Metadata: Logged as a native JSON object.
The community has truly embraced winston
; there are over 23 winston transports and over half of them are maintained by authors external to the winston core team. If you want to check them all out, just search npm
:
$ npm search winston
If you have an issue using one of these modules you should contact the module author directly
The winston-simpledb transport is just as easy:
var SimpleDB = require('winston-simpledb').SimpleDB; winston.add(SimpleDB, options);
The SimpleDB transport takes the following options. All items marked with an asterisk are required:
Metadata: Logged as a native JSON object to the 'meta' attribute of the item.
The winston-mail is an email transport:
var Mail = require('winston-mail').Mail; winston.add(Mail, options);
The Mail transport uses node-mail behind the scenes. Options are the following, to
and host
are required:
winston@[server-host-name]
)Metadata: Stringified as JSON in email.
The winston-sns transport uses amazon SNS to send emails, texts, or a bunch of other notifications.
require('winston-sns').SNS; winston.add(winston.transports.SNS, options);
Options:
us-east-1
,us-west-1
,eu-west-1
,ap-southeast-1
,ap-northeast-1
,us-gov-west-1
,sa-east-1
. (default: us-east-1
)info
)winston-graylog2 is a Graylog2 transport:
var Graylog2 = require('winston-graylog2').Graylog2; winston.add(Graylog2, options);
The Graylog2 transport connects to a Graylog2 server over UDP using the following options:
level: Level of messages this transport should log. (default: info)
silent: Boolean flag indicating whether to suppress output. (default: false)
graylogHost: IP address or hostname of the graylog2 server. (default: localhost)
graylogPort: Port to send messages to on the graylog2 server. (default: 12201)
graylogHostname: The hostname associated with graylog2 messages. (default: require('os').hostname())
graylogFacility: The graylog2 facility to send log messages.. (default: nodejs)
Metadata: Stringified as JSON in the full message GELF field.
winston-cassandra is a Cassandra transport:
var Cassandra = require('winston-cassandra').Cassandra; winston.add(Cassandra, options);
The Cassandra transport connects to a cluster using the native protocol with the following options:
'info'
).'logs'
).'hour'
and 'day'
(Default).quorum
).In addition to the options accepted by the Node.js Cassandra driver Client.
['host1', 'host2']
(required).$ npm search winston (...) winston-amon Winston transport for Amon logging =zoramite winston-amqp An AMQP transport for winston =kr1sp1n winston-cassandra A Cassandra transport for winston =jorgebay winston-couchdb a couchdb transport for winston =alz winston-express Express middleware to let you use winston from the browser. =regality winston-graylog2 A graylog2 transport for winston =smithclay winston-hbase A HBase transport for winston =ddude winston-loggly A Loggly transport for winston =indexzero winston-mail A mail transport for winston =wavded winston-mail2 A mail transport for winston =ivolo winston-mongodb A MongoDB transport for winston =indexzero winston-nodemail A mail transport for winston =reinpk winston-nssocket nssocket transport for winston =mmalecki winston-papertrail A Papertrail transport for winston =kenperkins winston-redis A fixed-length Redis transport for winston =indexzero winston-riak A Riak transport for winston =indexzero winston-scribe A scribe transport for winston =wnoronha winston-simpledb A Winston transport for Amazon SimpleDB =chilts winston-skywriter A Windows Azure table storage transport for winston =pofallon winston-sns A Simple Notification System Transport for winston =jesseditson winston-syslog A syslog transport for winston =indexzero winston-syslog-ain2 An ain2 based syslog transport for winston =lamtha winston-winlog Windows Event Log logger for Winston =jfromaniello winston-zmq A 0MQ transport for winston =dhendo winston-growl A growl transport for winston =pgherveou