smartlog-destination-local/index.js

112 lines
3.0 KiB
JavaScript
Raw 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-10-12 18:00:41 +00:00
var clc = require("cli-color");
2015-09-21 19:50:52 +00:00
var bl;
bl = {};
/**
* object to append to all locally used params
* @type {{}}
*/
var localBl;
localBl = {};
2015-10-12 18:00:41 +00:00
localBl.dirPrefix = clc.bgXterm(39).xterm(231).bold(' DIR ') + ' ';
2015-09-26 18:46:16 +00:00
localBl.errorPrefix = ' Error: '.bgRed.white.bold + ' ';
2015-10-12 18:00:41 +00:00
localBl.infoPrefix = clc.bgXterm(198).xterm(231).bold(' INFO ') + ' ';
2015-10-12 11:14:16 +00:00
localBl.normalPrefix = ' Log: '.bgCyan.white.bold + ' ';
localBl.okPrefix = ' '.bgGreen + ' OK! '.bgBlack.green.bold + ' ';
2015-09-26 18:46:16 +00:00
localBl.successPrefix = ' Success: '.bgGreen.white.bold + ' ';
2015-10-12 11:14:16 +00:00
localBl.warnPrefix = ' '.bgYellow + ' Warn: '.bgBlack.yellow.bold + ' ';
2015-09-21 19:50:52 +00:00
/**
*
* @param logText
* @param logType
* @returns {boolean}
*/
bl.log = function (logText, logType) {
2015-09-20 19:45:37 +00:00
if (logText === void 0) { logText = 'empty log'; }
if (logType === void 0) { logType = 'normal'; }
2015-09-21 19:50:52 +00:00
try {
switch (logType) {
2015-10-12 18:00:41 +00:00
case 'dir':
logText = localBl.dirPrefix + clc.xterm(26)(logText);
break;
2015-10-12 11:14:16 +00:00
case 'error':
logText = localBl.errorPrefix + logText.red.bold;
break;
2015-10-12 18:00:41 +00:00
case 'info':
logText = localBl.infoPrefix + clc.xterm(198)(logText);
break;
2015-09-21 19:50:52 +00:00
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-10-12 11:14:16 +00:00
case 'ok':
logText = localBl.okPrefix + logText.italic;
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;
2015-10-12 11:14:16 +00:00
case 'warn':
logText = localBl.warnPrefix + logText.italic;
break;
2015-09-26 17:34:01 +00:00
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;
2015-09-20 19:45:37 +00:00
}
2015-09-21 19:50:52 +00:00
catch (error) {
console.log(localBl.errorPrefix + 'You seem to have tried logging something strange'.red.bold + error);
return false;
}
};
2015-10-12 18:00:41 +00:00
/**
* logs an directory to console
* @param logText
* @returns {boolean}
*/
bl.dir = function (logText) {
return bl.log(logText, 'dir');
};
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');
};
2015-10-12 18:00:41 +00:00
/**
* logs an info to console
* @param logText
* @returns {boolean}
*/
bl.info = function (logText) {
return bl.log(logText, 'info');
};
2015-10-12 11:14:16 +00:00
/**
* logs an 'OK!' message to console
* @param logText
* @returns {boolean}
*/
bl.ok = function (logText) {
return bl.log(logText, 'ok');
};
2015-09-21 19:50:52 +00:00
/**
* logs a success to console
* @param logText string to log as error
* @returns {boolean}
*/
bl.success = function (logText) {
return bl.log(logText, 'success');
2015-09-20 17:21:29 +00:00
};
2015-10-12 11:14:16 +00:00
/**
* logs a 'warn:' message to console
* @param logText string to log as error
* @returns {boolean}
*/
bl.warn = function (logText) {
return bl.log(logText, 'warn');
};
2015-09-21 19:50:52 +00:00
module.exports = bl;