Skip to content

Instantly share code, notes, and snippets.

@indexzero
Last active August 29, 2015 14:19
Show Gist options
  • Save indexzero/6f81195cbfc069207659 to your computer and use it in GitHub Desktop.
Save indexzero/6f81195cbfc069207659 to your computer and use it in GitHub Desktop.
Concept for [email protected]
var format = winston.label()
.pipe(winston.timestamp())
.pipe(winston.colorize())
var logger = winston.logger({
transports: [
winston.file({
format: format,
})
.pipe(winston.gzip())
.pipe(winston.fileRotate()),
winston.console({
format: format
})
]
})
//
// Is equivalent to:
//
var logger = winston.logger({
format: format,
transports: [
winston.file()
.pipe(winston.gzip())
.pipe(winston.fileRotate()),
winston.console()
]
})

Logger is a duplex stream. The .pipe functionality removes the need for most of the _name bookkeeping in logger.js. All Transports become transform streams (in object-mode) for an object with well known properties, similar to what common.log expects now.

Transport objects pipe themselves to their .format property (if it exists) which a pipe-chain of other format Transform streams which all expect the same object format.

var stream = require('stream');

var Transport = modules.exports = function Transport(options) {
  //
  // Option 1: Have an output property for each stream which the logger
  // picks up on when calling `Logger.prototype.add`. The drawback to 
  // this is that the `Transport` itself isn't really a pipe source.
  //
  this.output = options.format ? this.pipe(options.format) : this;

  //
  // Options 2: Be a proper Transform stream
  //
  stream.Transform.call(this);
};

Transport.prototype._transform = function (obj) {
  
}

All current options formatting options in common.log

Formatting options in common.log

  • label
  • message
  • meta
  • showLevel
  • timestamp
  • raw
  • stripColors
  • json
  • logstash
  • stringify
  • formatter
  • filters
  • colorize
  • prettyPrint (with additional depth option)
  • humanReadableUnhandledException

DailyRotateFile

  • maxsize
  • maxFiles
  • datePattern
  • eol
  • maxRetries
  • filename
  • dirname
  • options
  • stream

File

  • maxsize
  • rotationFormat
  • tailable
  • eol
  • maxRetries
  • filename
  • dirname
  • options
  • stream

HTTP / Webhook

  • ssl
  • host
  • port
  • auth
  • path

Console

  • debugStdout

Other requested options

  • alignment of levels
  • string interpolation (e.g. "%s ok", 'foo')

Open questions

  • What is the difference between something like colorize and something like gzip.
  • How does fileRotate work given that it is actually a set of custom events on top of streams?
  • What are the exact details for the intermediate object format?
  • Can we actually even implement a Transform stream that handles an intermediate pipe-chain?
var winston = require('winston');
//
// Option 1: Have an output property for each stream.
//
var logger = winston.logger({
transports: [
winston.file({
format: winston.label()
.pipe(winston.timestamp())
.pipe(winston.colorize()),
})
.output
.pipe(winston.gzip())
.pipe(winston.fileRotate())
]
})
//
// Option 2: Transport is a proper Transform stream.
//
var logger = winston.logger({
transports: [
winston.file({
format: winston.label()
.pipe(winston.timestamp())
.pipe(winston.colorize()),
})
.pipe(winston.gzip())
.pipe(winston.fileRotate())
]
})
@pose
Copy link

pose commented May 12, 2015

Some notes from previous meetings:

transports (as a stream)
flush
close

logger events
logged event should be emitted by the
logging event -> individual transport completed a particular message

each of the transport
unit test log method signature that returns true
https://github.com/winstonjs/winston/blob/master/lib/winston/transports/memory.js#L82-L83

if transports are stream, transports no longer have a callback, optional one (like in write() stream).

We have to remove ‘logged’ transport events.

most of them will be writable streams

file transport: file stream wrapper that does a couple of extra thing

@indexzero
Copy link
Author

@pose
Copy link

pose commented Jun 2, 2015

Additional transports options:

CouchDB

  • db
  • host
  • port
  • auth
  • secure

MongoDB

  • db
  • options
  • server
  • collection
  • level
  • silent
  • username
  • password
  • storeHost
  • label
  • capped
  • cappedSize

Loggly

  • silent
  • stripColors
  • token
  • subdomain
  • tags
  • auth
  • json

Redis

  • socket_nodelay
  • socket_keepalive
  • command_queue_high_water
  • command_queue_low_water
  • max_attempts
  • connect_timeout
  • enable_offline_queue
  • retry_max_delay
  • auth_pass

SimpleDB

  • accessKeyId
  • secretAccessKey
  • awsAccountId
  • domainName
  • region
  • level
  • domainName
  • itemName

Mail

  • to
  • from
  • level
  • silent
  • subject
  • html
  • handleExceptions
  • username
  • options.password
  • port
  • host
  • ssl / secure
  • tls

SNS

  • aws_key
  • aws_secret
  • region
  • level
  • handleExceptions
  • json
  • subject
  • message
  • topic_arn

Graylog2

  • graylog
  • name
  • level
  • silent
  • handleExceptions

Cassandra

  • table
  • partitionBy
  • consistency
  • level
  • keyspace

Azure Table

  • account
  • key
  • useDevStorage
  • level
  • partitionKey
  • tableName
  • silent

Airbrake2

  • apiKey
  • level
  • host
  • env
  • timeout
  • developmentEnvironments
  • handleExceptions
  • projectRoot
  • appVersion
  • consoleLogError

Riak

  • debug
  • client
  • level
  • bucket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment