new warn and ok messages

This commit is contained in:
Phil Kunz 2015-10-12 13:14:16 +02:00
parent 0d3dc7e606
commit 4dbc481ef8
9 changed files with 176 additions and 9 deletions

View File

@ -8,9 +8,11 @@ bl = {};
*/ */
var localBl; var localBl;
localBl = {}; localBl = {};
localBl.normalPrefix = ' Log: '.bgCyan.white.bold + ' ';
localBl.errorPrefix = ' Error: '.bgRed.white.bold + ' '; localBl.errorPrefix = ' Error: '.bgRed.white.bold + ' ';
localBl.normalPrefix = ' Log: '.bgCyan.white.bold + ' ';
localBl.okPrefix = ' '.bgGreen + ' OK! '.bgBlack.green.bold + ' ';
localBl.successPrefix = ' Success: '.bgGreen.white.bold + ' '; localBl.successPrefix = ' Success: '.bgGreen.white.bold + ' ';
localBl.warnPrefix = ' '.bgYellow + ' Warn: '.bgBlack.yellow.bold + ' ';
/** /**
* *
* @param logText * @param logText
@ -22,15 +24,21 @@ bl.log = function (logText, logType) {
if (logType === void 0) { logType = 'normal'; } if (logType === void 0) { logType = 'normal'; }
try { try {
switch (logType) { switch (logType) {
case 'normal':
logText = localBl.normalPrefix + logText.cyan.bold;
break;
case 'error': case 'error':
logText = localBl.errorPrefix + logText.red.bold; logText = localBl.errorPrefix + logText.red.bold;
break; break;
case 'normal':
logText = localBl.normalPrefix + logText.cyan.bold;
break;
case 'ok':
logText = localBl.okPrefix + logText.italic;
break;
case 'success': case 'success':
logText = localBl.successPrefix + logText.green.bold; logText = localBl.successPrefix + logText.green.bold;
break; break;
case 'warn':
logText = localBl.warnPrefix + logText.italic;
break;
default: default:
logText.blue.bold; logText.blue.bold;
console.log(('unknown logType for "' + logText + '"').red.bold); console.log(('unknown logType for "' + logText + '"').red.bold);
@ -51,6 +59,14 @@ bl.log = function (logText, logType) {
bl.error = function (logText) { bl.error = function (logText) {
return bl.log(logText, 'error'); return bl.log(logText, 'error');
}; };
/**
* logs an 'OK!' message to console
* @param logText
* @returns {boolean}
*/
bl.ok = function (logText) {
return bl.log(logText, 'ok');
};
/** /**
* logs a success to console * logs a success to console
* @param logText string to log as error * @param logText string to log as error
@ -59,4 +75,12 @@ bl.error = function (logText) {
bl.success = function (logText) { bl.success = function (logText) {
return bl.log(logText, 'success'); return bl.log(logText, 'success');
}; };
/**
* logs a 'warn:' message to console
* @param logText string to log as error
* @returns {boolean}
*/
bl.warn = function (logText) {
return bl.log(logText, 'warn');
};
module.exports = bl; module.exports = bl;

View File

@ -4,7 +4,7 @@
"description": "beautiful logging", "description": "beautiful logging",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "cd ts/compile && gulp", "test": "(cd ts/compile && gulp) && (node test.js)",
"release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)" "release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)"
}, },
"repository": { "repository": {

View File

@ -5,11 +5,15 @@ console.log('');
console.log('declarative function calls:'); console.log('declarative function calls:');
beautyLog.log('beautylog.log(), with normal logText, without logType'); beautyLog.log('beautylog.log(), with normal logText, without logType');
beautyLog.error('beautylog.error(), with normal logText, without logType'); beautyLog.error('beautylog.error(), with normal logText, without logType');
beautyLog.ok('beautylog.ok(), with normal logText, without logType');
beautyLog.success('beautylog.success(), with normal logText, without logType'); beautyLog.success('beautylog.success(), with normal logText, without logType');
beautyLog.warn('beautylog.warn(), with normal logText, without logType');
console.log(''); console.log('');
console.log('logType String:'); console.log('logType String:');
beautyLog.log('beautylog.log(), with normal logText, without logType'); beautyLog.log('beautylog.log(), with normal logText, without logType');
beautyLog.log('beautylog.log(), with normal logText, with logType "error"', 'error'); beautyLog.log('beautylog.log(), with normal logText, with logType "error"', 'error');
beautyLog.log('beautylog.log(), with normal logText, with logType "ok"', 'ok');
beautyLog.log('beautylog.log(), with normal logText, with logType "success"', 'success'); beautyLog.log('beautylog.log(), with normal logText, with logType "success"', 'success');
beautyLog.log('beautylog.log(), with normal logText, with logType "warn"', 'warn');
console.log(''); console.log('');
console.log('*** end test ***'); console.log('*** end test ***');

87
ts/index.js Normal file
View File

@ -0,0 +1,87 @@
/// <reference path="./typings/tsd.d.ts" />
var colors = require("colors");
var bl;
bl = {};
/**
* object to append to all locally used params
* @type {{}}
*/
var localBl;
localBl = {};
localBl.errorPrefix = ' Error: '.bgRed.white.bold + ' ';
localBl.normalPrefix = ' Log: '.bgCyan.white.bold + ' ';
localBl.okPrefix = ' '.bgGreen + ' OK! '.bgBlack.green.bold + ' ';
localBl.successPrefix = ' Success: '.bgGreen.white.bold + ' ';
localBl.warnPrefix = ' '.bgYellow + ' Warn: '.bgBlack.yellow.bold + ' ';
/**
*
* @param logText
* @param logType
* @returns {boolean}
*/
bl.log = function (logText, logType) {
if (logText === void 0) { logText = 'empty log'; }
if (logType === void 0) { logType = 'normal'; }
try {
switch (logType) {
case 'error':
logText = localBl.errorPrefix + logText.red.bold;
break;
case 'normal':
logText = localBl.normalPrefix + logText.cyan.bold;
break;
case 'ok':
logText = localBl.okPrefix + logText.italic;
break;
case 'success':
logText = localBl.successPrefix + logText.green.bold;
break;
case 'warn':
logText = localBl.warnPrefix + logText.italic;
break;
default:
logText.blue.bold;
console.log(('unknown logType for "' + logText + '"').red.bold);
}
console.log(logText);
return true;
}
catch (error) {
console.log(localBl.errorPrefix + 'You seem to have tried logging something strange'.red.bold + error);
return false;
}
};
/**
* logs an error to console
* @param logText
* @returns {boolean}
*/
bl.error = function (logText) {
return bl.log(logText, 'error');
};
/**
* logs an 'OK!' message to console
* @param logText
* @returns {boolean}
*/
bl.ok = function (logText) {
return bl.log(logText, 'ok');
};
/**
* logs a success to console
* @param logText string to log as error
* @returns {boolean}
*/
bl.success = function (logText) {
return bl.log(logText, 'success');
};
/**
* logs a 'warn:' message to console
* @param logText string to log as error
* @returns {boolean}
*/
bl.warn = function (logText) {
return bl.log(logText, 'warn');
};
module.exports = bl;
//# sourceMappingURL=index.js.map

1
ts/index.js.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":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,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACnC,CAAC,CAAA;AAED,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC"}

View File

@ -11,9 +11,11 @@ bl = {}
*/ */
var localBl:any; var localBl:any;
localBl = {}; localBl = {};
localBl.normalPrefix = ' Log: '.bgCyan.white.bold + ' ';
localBl.errorPrefix = ' Error: '.bgRed.white.bold + ' '; localBl.errorPrefix = ' Error: '.bgRed.white.bold + ' ';
localBl.normalPrefix = ' Log: '.bgCyan.white.bold + ' ';
localBl.okPrefix = ' '.bgGreen + ' OK! '.bgBlack.green.bold + ' ';
localBl.successPrefix = ' Success: '.bgGreen.white.bold + ' '; localBl.successPrefix = ' Success: '.bgGreen.white.bold + ' ';
localBl.warnPrefix = ' '.bgYellow + ' Warn: '.bgBlack.yellow.bold + ' ';
/** /**
* *
@ -24,15 +26,21 @@ localBl.successPrefix = ' Success: '.bgGreen.white.bold + ' ';
bl.log = (logText:string = 'empty log',logType:string = 'normal') => { bl.log = (logText:string = 'empty log',logType:string = 'normal') => {
try { try {
switch (logType) { switch (logType) {
case 'normal':
logText = localBl.normalPrefix + logText.cyan.bold;
break;
case 'error': case 'error':
logText = localBl.errorPrefix + logText.red.bold; logText = localBl.errorPrefix + logText.red.bold;
break; break;
case 'normal':
logText = localBl.normalPrefix + logText.cyan.bold;
break;
case 'ok':
logText = localBl.okPrefix + logText.italic;
break;
case 'success': case 'success':
logText = localBl.successPrefix + logText.green.bold; logText = localBl.successPrefix + logText.green.bold;
break; break;
case 'warn':
logText = localBl.warnPrefix + logText.italic;
break;
default: default:
logText.blue.bold; logText.blue.bold;
console.log(('unknown logType for "' + logText + '"').red.bold); console.log(('unknown logType for "' + logText + '"').red.bold);
@ -56,6 +64,15 @@ bl.error = function(logText) {
return bl.log(logText, 'error'); return bl.log(logText, 'error');
}; };
/**
* logs an 'OK!' message to console
* @param logText
* @returns {boolean}
*/
bl.ok = function(logText) {
return bl.log(logText, 'ok');
};
/** /**
* logs a success to console * logs a success to console
* @param logText string to log as error * @param logText string to log as error
@ -65,4 +82,13 @@ bl.success = function(logText) {
return bl.log(logText, 'success'); return bl.log(logText, 'success');
} }
/**
* logs a 'warn:' message to console
* @param logText string to log as error
* @returns {boolean}
*/
bl.warn = function(logText) {
return bl.log(logText, 'warn');
}
module.exports = bl; module.exports = bl;

20
ts/test.js Normal file
View File

@ -0,0 +1,20 @@
/// <reference path="./typings/tsd.d.ts" />
var beautyLog = require('./index.js');
console.log('*** start test ***');
console.log('');
console.log('declarative function calls:');
beautyLog.log('beautylog.log(), with normal logText, without logType');
beautyLog.error('beautylog.error(), with normal logText, without logType');
beautyLog.ok('beautylog.ok(), with normal logText, without logType');
beautyLog.success('beautylog.success(), with normal logText, without logType');
beautyLog.warn('beautylog.warn(), with normal logText, without logType');
console.log('');
console.log('logType String:');
beautyLog.log('beautylog.log(), with normal logText, without logType');
beautyLog.log('beautylog.log(), with normal logText, with logType "error"', 'error');
beautyLog.log('beautylog.log(), with normal logText, with logType "ok"', 'ok');
beautyLog.log('beautylog.log(), with normal logText, with logType "success"', 'success');
beautyLog.log('beautylog.log(), with normal logText, with logType "warn"', 'warn');
console.log('');
console.log('*** end test ***');
//# sourceMappingURL=test.js.map

1
ts/test.js.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,IAAI,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAEtC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAClC,OAAO,CAAC,GAAG,CAAE,EAAE,CAAC,CAAC;AAEjB,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAC3C,SAAS,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;AACvE,SAAS,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;AAC3E,SAAS,CAAC,EAAE,CAAC,sDAAsD,CAAC,CAAC;AACrE,SAAS,CAAC,OAAO,CAAC,2DAA2D,CAAC,CAAC;AAC/E,SAAS,CAAC,IAAI,CAAC,wDAAwD,CAAC,CAAC;AAEzE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAEhB,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAC/B,SAAS,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;AACvE,SAAS,CAAC,GAAG,CAAC,4DAA4D,EAAC,OAAO,CAAC,CAAC;AACpF,SAAS,CAAC,GAAG,CAAC,yDAAyD,EAAC,IAAI,CAAC,CAAC;AAC9E,SAAS,CAAC,GAAG,CAAC,8DAA8D,EAAC,SAAS,CAAC,CAAC;AACxF,SAAS,CAAC,GAAG,CAAC,2DAA2D,EAAC,MAAM,CAAC,CAAC;AAElF,OAAO,CAAC,GAAG,CAAE,EAAE,CAAC,CAAC;AACjB,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC"}

View File

@ -7,14 +7,18 @@ console.log ('');
console.log('declarative function calls:'); console.log('declarative function calls:');
beautyLog.log('beautylog.log(), with normal logText, without logType'); beautyLog.log('beautylog.log(), with normal logText, without logType');
beautyLog.error('beautylog.error(), with normal logText, without logType'); beautyLog.error('beautylog.error(), with normal logText, without logType');
beautyLog.ok('beautylog.ok(), with normal logText, without logType');
beautyLog.success('beautylog.success(), with normal logText, without logType'); beautyLog.success('beautylog.success(), with normal logText, without logType');
beautyLog.warn('beautylog.warn(), with normal logText, without logType');
console.log(''); console.log('');
console.log('logType String:'); console.log('logType String:');
beautyLog.log('beautylog.log(), with normal logText, without logType'); beautyLog.log('beautylog.log(), with normal logText, without logType');
beautyLog.log('beautylog.log(), with normal logText, with logType "error"','error'); beautyLog.log('beautylog.log(), with normal logText, with logType "error"','error');
beautyLog.log('beautylog.log(), with normal logText, with logType "ok"','ok');
beautyLog.log('beautylog.log(), with normal logText, with logType "success"','success'); beautyLog.log('beautylog.log(), with normal logText, with logType "success"','success');
beautyLog.log('beautylog.log(), with normal logText, with logType "warn"','warn');
console.log (''); console.log ('');
console.log('*** end test ***'); console.log('*** end test ***');