smartlog-destination-local/ts/index.ts

69 lines
1.6 KiB
TypeScript
Raw Permalink Normal View History

2015-09-26 17:34:01 +00:00
/// <reference path="./typings/tsd.d.ts" />
2015-09-20 19:45:37 +00:00
var colors = require("colors");
2015-09-20 17:21:29 +00:00
2015-09-21 19:50:52 +00:00
var bl:any;
bl = {}
/**
* object to append to all locally used params
* @type {{}}
*/
var localBl:any;
localBl = {};
2015-09-26 18:46:16 +00:00
localBl.normalPrefix = ' Log: '.bgCyan.white.bold + ' ';
localBl.errorPrefix = ' Error: '.bgRed.white.bold + ' ';
localBl.successPrefix = ' Success: '.bgGreen.white.bold + ' ';
2015-09-21 19:50:52 +00:00
/**
*
* @param logText
* @param logType
* @returns {boolean}
*/
bl.log = (logText:string = 'empty log',logType:string = 'normal') => {
try {
switch (logType) {
case 'normal':
2015-09-26 18:46:16 +00:00
logText = localBl.normalPrefix + logText.cyan.bold;
2015-09-26 17:34:01 +00:00
break;
2015-09-21 19:50:52 +00:00
case 'error':
logText = localBl.errorPrefix + logText.red.bold;
2015-09-26 17:34:01 +00:00
break;
2015-09-21 19:50:52 +00:00
case 'success':
2015-09-26 18:46:16 +00:00
logText = localBl.successPrefix + logText.green.bold;
2015-09-26 17:34:01 +00:00
break;
default:
logText.blue.bold;
console.log(('unknown logType for "' + logText + '"').red.bold);
2015-09-21 19:50:52 +00:00
}
console.log(logText);
return true;
}
catch(error) {
console.log(localBl.errorPrefix + 'You seem to have tried logging something strange'.red.bold + error);
return false;
2015-09-20 19:45:37 +00:00
}
2015-09-20 17:21:29 +00:00
};
2015-09-21 19:50:52 +00:00
/**
* logs an error to console
* @param logText
* @returns {boolean}
*/
bl.error = function(logText) {
return bl.log(logText, 'error');
};
/**
* logs a success to console
* @param logText string to log as error
* @returns {boolean}
*/
bl.success = function(logText) {
return bl.log(logText, 'success');
}
module.exports = bl;