var settings = require('./settings');
var process = require('process');
try { var colors = require('colors'); } catch(e) {var colors = false;}



LEVELS = {
	'debug' : 0,
	'info' : 1,
	'warn' : 2,
	'error' : 3,
};

LOG_LEVELS = {
	'g2' : 'debug',
	'gcode' : 'debug',
	'sbp' : 'debug',
	'machine' : 'debug',
	'manual' : 'debug',
	'api' : 'debug',
	'detection' :'debug',
	'config_loader' : 'debug',
	'settings' : 'debug',
	'log':'debug'
};

function setGlobalLevel(lvl){
	if (lvl)
	{
		if (lvl >= 0 && lvl <= 3)
		{
			// assign the log level to the string equivalent of the integer 
			Object.keys(LOG_LEVELS).forEach(function(key) {
	  			LOG_LEVELS[key] = Object.keys(LEVELS).filter(function(key) {return (LEVELS[key] === lvl);})[0];
	  		});
		}
		else if (Object.keys(LEVELS).indexOf(lvl) >= 0) // if a string
		{
			//  assign the log level to the string that is given 
			Object.keys(LOG_LEVELS).forEach(function(key) {
	  			LOG_LEVELS[key] = lvl;
	  		});
		}
		else if (lvl === "none")
		{
			return;
		}
		else
		{
			logger('log').warn('wrong debug level for logging !');
		}
	}
}


var logs = {};

var Logger = function(name) {
	this.name = name;
};

Logger.prototype.write = function(level, msg) {
	my_level = LOG_LEVELS[this.name] || 'debug';
	if((LEVELS[level] || 0) >= (LEVELS[my_level] || 0)) {
		if(colors) {
			switch(level) {
				case 'debug':
					console.log((level + ': ').blue + msg+' ['+this.name+']');
					break;
				case 'info':
					console.log((level + ': ').green + msg+' ['+this.name+']');
					break;
				case 'warn':
					console.log((level + ': ').yellow + msg+' ['+this.name+']');
					break;
				case 'error':
					console.log((level + ': ').red + msg+' ['+this.name+']');
					break;
			}
		} else {
			console.log(level + ': ' + msg+' ['+this.name+']');
		}
	}
};

Logger.prototype.debug = function(msg) {
	this.write('debug', msg);
};

Logger.prototype.info = function(msg) {
	this.write('info', msg);
};

Logger.prototype.warn = function(msg) {
	this.write('warn', msg);
};

Logger.prototype.error = function(msg) {
	this.write('error', msg);
};

var logger = function(name) {
	if(name in logs) {
		return logs[name];
	} else {
		l = new Logger(name);
		logs[name] = l;
		return l;
	}
};
/*
process.on('uncaughtException', function(err) {
	if(colors) {
		console.log(err.red);
	}
	else {
		console.log(err);
	}

});*/

exports.logger = logger;
exports.setGlobalLevel = setGlobalLevel;
 

@@ -1,12 +1,155 @@
+/** %0A * log.js is a %22Poor man's%22 logging module.  It provides basic colorized logging using named %0A * loggers with selectable log levelts.%0A */%0A
 var settings
@@ -280,17 +280,62 @@
 alse;%7D%0A%0A
-%0A
+// String versions of the allowable log levels
 %0ALEVELS 
@@ -396,16 +396,71 @@
  3,%0A%7D;%0A%0A
+// Default log levels for loggers with specific names.%0A
 LOG_LEVE
@@ -1287,40 +1287,34 @@
 rn('
-wrong debug level for logging !'
+Invalid log level: ' + lvl
 );%0A%09
@@ -1326,77 +1326,306 @@
 %0A%7D%0A%0A
-%0A
-var logs = %7B%7D;%0A%0Avar Logger = function(name) %7B%0A%09this.name = name;%0A%7D;%0A
+// The Logger object is what is created and used by modules to log to the console.%0Avar Logger = function(name) %7B%0A%09this.name = name;%0A%7D;%0A%0A// Index of all the Logger objects that have been created.%0Avar logs = %7B%7D;%0A%0A// Output the provided message with colorized output (if available) and the logger name
 %0ALog
@@ -2258,24 +2258,114 @@
 %0A%09%09%7D%0A%09%7D%0A%7D;%0A%0A
+// These functions provide a shorthand alternative to specifying the log level every time%0A
 Logger.proto
@@ -2384,34 +2384,33 @@
  function(msg) %7B
-%0A%09
+ 
 this.write('debu
@@ -2410,37 +2410,36 @@
 e('debug', msg);
-%0A
+ 
 %7D;%0A
-%0A
 Logger.prototype
@@ -2453,34 +2453,33 @@
  function(msg) %7B
-%0A%09
+ 
 this.write('info
@@ -2478,37 +2478,36 @@
 te('info', msg);
-%0A
+ 
 %7D;%0A
-%0A
 Logger.prototype
@@ -2521,34 +2521,33 @@
  function(msg) %7B
-%0A%09
+ 
 this.write('warn
@@ -2554,21 +2554,20 @@
 ', msg);
-%0A
+ 
 %7D;%0A
-%0A
 Logger.p
@@ -2598,18 +2598,17 @@
 n(msg) %7B
-%0A%09
+ 
 this.wri
@@ -2624,21 +2624,81 @@
 ', msg);
-%0A
 %7D;%0A%0A
+// Factory function for producing a new, named logger object%0A
 var logg
@@ -2830,16 +2830,17 @@
 ;%0A%09%7D%0A%7D;%0A
+%0A
 /*%0Aproce

Add docs to log.js