var events = require('events');
var os = require('os');
var path = require('path'),
  basename = path.basename;
var util = require('util');
var merge = require('cli-util').merge;

var levels = {
  trace: 10,
  debug: 20,
  info: 30,
  warn: 40,
  error: 50,
  fatal: 60
}

var defaults = {
  name: basename(process.argv[1]),
  json: true
}

/**
 *  Create a Logger instance.
 *
 *  @param conf The logger configuration.
 */
var Logger = function(conf) {
  conf = conf || {};
  this.conf = merge(conf, merge(defaults, {}));
  this.pid = process.pid;
  this.hostname = os.hostname();
}

util.inherits(Logger, events.EventEmitter);

/**
 *  Retrieve a log record.
 *
 *  @api private
 *
 *  @param level The log level.
 *  @param message The log message.
 *  @param ... The message replacement parameters.
 */
Logger.prototype.getLogRecord = function(level, message) {
  var parameters = [].slice.call(arguments, 2);
  if(parameters.length) {
    parameters.unshift(message);
    message = util.format.apply(util, parameters);
  }
  var record = message;
  if(this.conf.json) {
    record = {
      pid: this.pid,
      hostname: this.hostname,
      name: this.conf.name,
      msg: message,
      level: level,
      time: new Date().toISOString()
    };
  }
  console.log('logging message...%j', record);
}

/**
 *  Log a message.
 *
 *  @api private
 *
 *  @param level The log level.
 *  @param message The log message.
 *  @param ... The message replacement parameters.
 */
Logger.prototype.log = function(level, message) {
  if(!message) return false;
  var record = this.getLogRecord.apply(this, arguments);
  //console.log('logging message...%s', message);
}

/**
 *  Log an info message.
 *
 *  @param message The log message.
 *  @param ... The message replacement parameters.
 */
Logger.prototype.info = function() {
  var args = [].slice.call(arguments, 0);
  args.unshift(levels.info);
  this.log.apply(this, args);
}

module.exports = function(conf) {
  var logger = new Logger(conf);
  return logger;
}

module.exports.Logger = Logger;

@@ -21,24 +21,48 @@
 ('events');%0A
+var fs = require('fs');%0A
 var os = req
@@ -153,24 +153,67 @@
 re('util');%0A
+var Writable = require('stream').Writable;%0A
 var merge = 
@@ -541,159 +541,1139 @@
 ;%0A  
-this.conf = merge(conf, merge(defaults, %7B%7D));%0A  this.pid = process.pid;%0A  this.hostname = os.hostname();%0A%7D%0A%0Autil.inherits(Logger, events.EventEmitter);
+function filter(t, k, v) %7B%0A    if(k !== 'streams') %7B%0A      t%5Bk%5D = v;%0A    %7D%0A  %7D%0A  this.conf = merge(conf, merge(defaults, %7B%7D), filter);%0A  this.conf.streams = this.conf.streams %7C%7C %7B%0A    stream: process.stdout,%0A    level: levels.info%0A  %7D%0A  this.streams = this.initialize();%0A  this.pid = process.pid;%0A  this.hostname = os.hostname();%0A%7D%0A%0Autil.inherits(Logger, events.EventEmitter);%0A%0A/**%0A *  Initialize the output streams.%0A *%0A *  @api private%0A */%0ALogger.prototype.initialize = function() %7B%0A  var streams = %5B%5D;%0A  var conf = this.conf;%0A  var source = this.conf.streams;%0A  function append(stream, level, name) %7B%0A    streams.push(%7Bstream: stream, level: level %7C%7C levels.info, name: name%7D)%0A  %7D%0A  function wrap(source) %7B%0A    append(source.stream, source.level, source.name %7C%7C conf.name);%0A  %7D%0A  if(source && typeof(source) == 'object' && !Array.isArray(source)) %7B%0A    if((source.stream instanceof Writable)%0A      %7C%7C source.stream === process.stdout%0A      %7C%7C source.stream === process.stderr) %7B%0A      wrap(source);%0A    %7D%0A  %7Delse if(Array.isArray(source)) %7B%0A    source.forEach(function(source) %7B%0A      wrap(source);%0A    %7D)%0A  %7D%0A  return streams;%0A%7D
 %0A%0A/*

Initialize output streams.