2015-05-05 05:59:48 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var util = require('util');
|
|
|
|
var chalk = require('chalk');
|
|
|
|
|
|
|
|
var signs = [
|
|
|
|
'==>',
|
|
|
|
'!!!',
|
|
|
|
'xx>',
|
|
|
|
'===',
|
|
|
|
'>>>',
|
2015-05-05 08:04:27 +02:00
|
|
|
'xxx',
|
|
|
|
'=H='
|
2015-05-05 05:59:48 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
var types = [
|
|
|
|
'eth',
|
|
|
|
'wsc',
|
|
|
|
'sys',
|
|
|
|
'his'
|
|
|
|
];
|
|
|
|
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: "info",
|
|
|
|
sign: '=i=',
|
|
|
|
signColor: chalk.blue,
|
|
|
|
messageColor: chalk.bold,
|
|
|
|
formatter: function (sign, message)
|
|
|
|
{
|
|
|
|
return [sign, message];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "success",
|
|
|
|
inherit: 'log',
|
2015-05-06 06:15:58 +02:00
|
|
|
sign: '=✓=',
|
2015-05-05 05:59:48 +02:00
|
|
|
signColor: chalk.green,
|
|
|
|
messageColor: chalk.bold.green,
|
|
|
|
formatter: function (sign, message)
|
|
|
|
{
|
|
|
|
return [sign, message];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "warn",
|
2015-05-11 19:55:12 +02:00
|
|
|
sign: '=!=',
|
2015-05-05 05:59:48 +02:00
|
|
|
signColor: chalk.yellow,
|
|
|
|
messageColor: chalk.bold.yellow,
|
|
|
|
formatter: function (sign, message)
|
|
|
|
{
|
|
|
|
return [sign, message];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "error",
|
2015-05-06 06:15:58 +02:00
|
|
|
sign: '=✘=',
|
2015-05-05 05:59:48 +02:00
|
|
|
signColor: chalk.red,
|
|
|
|
messageColor: chalk.bold.red,
|
|
|
|
formatter: function (sign, message)
|
|
|
|
{
|
|
|
|
return [sign, message];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "time",
|
|
|
|
sign: '=T=',
|
|
|
|
signColor: chalk.cyan,
|
|
|
|
messageColor: chalk.bold,
|
|
|
|
formatter: function (sign, message)
|
|
|
|
{
|
|
|
|
return [util.format.apply(util, [sign, message])];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "timeEnd",
|
|
|
|
sign: '=T=',
|
|
|
|
signColor: chalk.cyan,
|
|
|
|
messageColor: chalk.bold,
|
|
|
|
formatter: function (sign, message)
|
|
|
|
{
|
|
|
|
return [util.format.apply(util, [sign, message])];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
].forEach( function (item)
|
|
|
|
{
|
|
|
|
if(item.inherit !== undefined)
|
|
|
|
console[item.name] = console[item.inherit];
|
|
|
|
|
|
|
|
var fn = console[item.name];
|
|
|
|
|
|
|
|
console[item.name] = function ()
|
|
|
|
{
|
|
|
|
var args = Array.prototype.slice.call(arguments);
|
|
|
|
var sign = item.sign;
|
|
|
|
var section = 'eth';
|
|
|
|
var message = '';
|
|
|
|
|
|
|
|
if (signs.indexOf(args[0]) >= 0)
|
|
|
|
{
|
|
|
|
sign = args.splice(0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (types.indexOf(args[0]) >= 0)
|
|
|
|
{
|
|
|
|
section = args.splice(0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sign = item.signColor( '[' + section + '] ' + sign );
|
|
|
|
|
|
|
|
if (typeof args[0] === 'object')
|
|
|
|
{
|
|
|
|
message = util.inspect( args[0], { depth: null, colors: true } );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
message = item.messageColor( util.format.apply(util, args) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return fn.apply( this, item.formatter(sign, message) );
|
|
|
|
}
|
|
|
|
});
|