smartlog-destination-local/dist/beautylog.log.helpers.js
2016-07-24 01:17:38 +02:00

106 lines
8.6 KiB
JavaScript

"use strict";
const plugins = require("./beautylog.plugins");
const beautylog_console_1 = require("./beautylog.console");
const beautylog_remote_1 = require("./beautylog.remote");
/**
*
* @param logText
* @param logType
* @returns {boolean}
*/
exports.internalLog = function (logType = 'normal', logText = 'empty log') {
switch (plugins.smartenv.getEnv().runtimeEnv) {
case "node":
exports.logNode(logType, logText);
beautylog_remote_1.remoteLog(logType, logText);
break;
case "browser":
logBrowser(logText, logType);
break;
default:
console.log("something is strange about the platform in which you try to use beautylog");
break;
}
;
};
let localBl = {
dirPrefix: plugins.clc.bgXterm(39).xterm(231).bold(' DIR ') + ' ',
errorPrefix: ' Error: '.bgRed.white.bold + ' ',
infoPrefix: plugins.clc.bgXterm(198).xterm(231).bold(' INFO ') + ' ',
normalPrefix: ' Log: '.bgCyan.white.bold + ' ',
okPrefix: ' '.bgGreen + ' OK! '.bgBlack.green.bold + ' ',
successPrefix: ' Success: '.bgGreen.white.bold + ' ',
warnPrefix: ' '.bgYellow + ' Warn: '.bgBlack.yellow.bold + ' '
};
exports.logNode = function (logType, logText) {
try {
switch (logType) {
case 'dir':
logText = localBl.dirPrefix + plugins.clc.xterm(26)(logText);
break;
case 'error':
logText = localBl.errorPrefix + logText.red.bold;
break;
case 'info':
logText = localBl.infoPrefix + plugins.clc.xterm(198)(logText);
break;
case 'normal':
logText = localBl.normalPrefix + logText.cyan.bold;
break;
case 'ok':
logText = localBl.okPrefix + logText.bold;
break;
case 'success':
logText = localBl.successPrefix + logText.green.bold;
break;
case 'warn':
logText = localBl.warnPrefix + logText.bold;
break;
case 'log':
logText = localBl.normalPrefix + logText.blue.bold;
break;
default:
logText.blue.bold;
console.log(('unknown logType for "' + logText + '"').red.bold);
break;
}
beautylog_console_1.beautyConsole.log(logText);
return true;
}
catch (error) {
console.log(localBl.errorPrefix + 'You seem to have tried logging something strange'.red.bold + error);
return false;
}
};
let logBrowser = function (logText, logType) {
switch (logType) {
case 'dir':
logText = localBl.dirPrefix + plugins.clc.xterm(26)(logText);
break;
case 'error':
logText = localBl.errorPrefix + logText.red.bold;
break;
case 'info':
console.log('%c Info: %c ' + logText, 'background:#EC407A;color:#ffffff;', 'color:#EC407A;');
break;
case 'normal':
logText = localBl.normalPrefix + logText.cyan.bold;
break;
case 'ok':
console.log('%c OK: %c ' + logText, "background:#000000;color:#8BC34A;", "color:#000000;");
break;
case 'success':
console.log('%c Success: %c ' + logText, "background:#8BC34A;color:#ffffff;", "color:#8BC34A;");
break;
case 'warn':
console.log('%c Warn: %c ' + logText, "background:#000000;color:#FB8C00;", "color:#000000;");
break;
case 'log':
console.log('%c Log: %c ' + logText, "background:#42A5F5;color:#ffffff", "color:#42A5F5;");
break;
default:
console.log('unknown logType for "' + logText + '"');
break;
}
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmVhdXR5bG9nLmxvZy5oZWxwZXJzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvYmVhdXR5bG9nLmxvZy5oZWxwZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxxQkFBcUIsQ0FBQyxDQUFBO0FBQy9DLG9DQUE4QixxQkFBcUIsQ0FBQyxDQUFBO0FBQ3BELG1DQUF3QixvQkFBb0IsQ0FBQyxDQUFBO0FBRTdDOzs7OztHQUtHO0FBQ1EsbUJBQVcsR0FBRyxVQUFVLE9BQU8sR0FBVyxRQUFRLEVBQUUsT0FBTyxHQUFXLFdBQVc7SUFDeEYsTUFBTSxDQUFDLENBQUMsT0FBTyxDQUFDLFFBQVEsQ0FBQyxNQUFNLEVBQUUsQ0FBQyxVQUFVLENBQUMsQ0FBQSxDQUFDO1FBQzFDLEtBQUssTUFBTTtZQUNQLGVBQU8sQ0FBQyxPQUFPLEVBQUMsT0FBTyxDQUFDLENBQUM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