Comparing version 0.1.0 to 0.2.0
@@ -1,2 +0,3 @@ | ||
var names = [] | ||
var human = {} | ||
, names = [] | ||
, skips = [] | ||
@@ -6,3 +7,3 @@ | ||
// used to do (and still does, hopefully). | ||
(process.env.DEBUG || '') | ||
;(process.env.DEBUG || '') | ||
.split(/[\s,]+/) | ||
@@ -47,1 +48,47 @@ .forEach(function(name){ | ||
} | ||
/** | ||
* Returns the level of the provided `chunk`. | ||
*/ | ||
function getLevel(chunk) { | ||
var matches = /"level":"([^\"]*)"/.exec(chunk) | ||
return matches ? matches[1] : null | ||
} | ||
/** | ||
* Returns the name of the provided `chunk`'s Mill. | ||
*/ | ||
function getMill(chunk) { | ||
var matches = /"mill":"([^\"]*)"/.exec(chunk) | ||
return matches ? matches[1] : null | ||
} | ||
/** | ||
* Write the provided `chunk`. | ||
*/ | ||
human.write = write | ||
function write(chunk) { | ||
var level = getLevel(chunk) | ||
, mill = getMill(chunk) | ||
if (!level || !mill) { | ||
return | ||
} | ||
switch (level) { | ||
case 'debug': | ||
if (shouldDebug(mill)) { | ||
process.stdout.write(chunk) | ||
} | ||
break | ||
case 'info': | ||
case 'warn': | ||
process.stdout.write(chunk) | ||
break | ||
case 'error': | ||
process.stderr.write(chunk) | ||
break | ||
} | ||
} | ||
module.exports = human |
@@ -14,14 +14,10 @@ /*! | ||
/** | ||
* Creates a new instance of Mill with the provided `options`. | ||
* | ||
* @param {Object} obj | ||
* Creates a new instance of Mill with the provided `name`. | ||
*/ | ||
function Mill(obj) { | ||
function Mill(name) { | ||
if (!(this instanceof Mill)) { | ||
return new Mill(obj) | ||
return new Mill(name) | ||
} | ||
obj = obj || {} | ||
this.name = obj.name || 'Unknown' | ||
this.name = name || 'Unknown' | ||
this.streams = [] | ||
@@ -73,6 +69,2 @@ } | ||
function send(level, body) { | ||
if (level === 'debug' && !this.debugging) { | ||
return this | ||
} | ||
this.streams.forEach(function (obj) { | ||
@@ -83,3 +75,3 @@ if (LEVELS[level] > LEVELS[obj.level]) { | ||
obj.stream.write(JSON.stringify(body)) | ||
obj.stream.write(JSON.stringify(body) + '\n') | ||
}) | ||
@@ -96,3 +88,3 @@ | ||
Mill.prototype[level] = function log() { | ||
return this.send(level, this.createBody(arguments)) | ||
return this.send(level, this.createBody(level, arguments)) | ||
} | ||
@@ -119,3 +111,3 @@ }) | ||
body = this.createBody(arguments) | ||
body = this.createBody('debug', arguments) | ||
body.stack = stack | ||
@@ -126,2 +118,30 @@ | ||
/** | ||
* Adds `stream` as `name` to the output streams at the provided `level`. | ||
*/ | ||
Mill.prototype.add = add | ||
function add(name, stream, level) { | ||
this.streams.push({ | ||
name: name, | ||
stream: stream, | ||
level: level || 'info' | ||
}) | ||
return this | ||
} | ||
/** | ||
* Removes the stream (or streams) with `name`. | ||
*/ | ||
Mill.prototype.remove = remove | ||
function remove(name) { | ||
var streams = this.streams | ||
streams.forEach(function (obj, index) { | ||
if (obj.name === name) { | ||
streams.splice(index, 1) | ||
} | ||
}) | ||
} | ||
/*! | ||
@@ -128,0 +148,0 @@ * Export `Mill`. |
{ | ||
"name": "sawmill", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Where logs go to be cut up and sent elsewhere.", | ||
"main": "index.js", | ||
"main": "lib/sawmill.js", | ||
"scripts": { | ||
"test": "mocha --reporter spec" | ||
"test": "mocha --ui exports --reporter spec" | ||
}, | ||
@@ -16,3 +16,8 @@ "repository": "", | ||
"author": "Michael Schoonmaker <michael.r.schoonmaker@gmail.com>", | ||
"license": "MIT" | ||
"license": "MIT", | ||
"devDependencies": { | ||
"nexpect": "~0.3.0", | ||
"mocha": "~1.16.2", | ||
"once-later": "~1.0.1" | ||
} | ||
} |
14246
12
263
3