smartlog-destination-local/dist/beautylog.log.helpers.js
2016-10-16 02:26:43 +02:00

114 lines
10 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 xC = {
black: 232,
blue: 39,
cyan: 87,
green: 112,
red: 196,
white: 231,
};
let localBl = {
dirPrefix: plugins.clc.bgXterm(xC.blue).xterm(xC.white).bold(' DIR ') + ' ',
errorPrefix: plugins.clc.bgXterm(xC.red)(' ') + plugins.clc.bgXterm(xC.black).xterm(xC.red).bold(' Error: ') + ' ',
infoPrefix: plugins.clc.bgXterm(198).xterm(231).bold(' INFO ') + ' ',
logPrefix: plugins.clc.bgXterm(xC.cyan)(' ') + plugins.clc.bgXterm(xC.black).xterm(xC.cyan).bold(' Log: ') + ' ',
okPrefix: plugins.clc.bgXterm(xC.green)(' ') + plugins.clc.bgXterm(xC.black).xterm(xC.green).bold(' OK! ') + ' ',
successPrefix: plugins.clc.bgXterm(xC.green)(' ') + plugins.clc.bgXterm(xC.black).xterm(xC.green).bold(' Success: ') + ' ',
warnPrefix: plugins.clc.bgYellow(' ') + plugins.clc.bgBlack.yellow.bold(' Warn: ') + ' '
};
exports.logNode = function (logType, logText) {
try {
switch (logType) {
case 'dir':
logText = localBl.dirPrefix + plugins.clc.xterm(xC.blue)(logText);
break;
case 'error':
logText = localBl.errorPrefix + plugins.clc.xterm(xC.red).bold(logText);
break;
case 'info':
logText = localBl.infoPrefix + plugins.clc.xterm(198)(logText);
break;
case 'normal':
logText = localBl.logPrefix + plugins.clc.xterm(xC.cyan).bold(logText);
break;
case 'ok':
logText = localBl.okPrefix + plugins.clc.bold(logText);
break;
case 'success':
logText = localBl.successPrefix + plugins.clc.xterm(xC.green).bold(logText);
break;
case 'warn':
logText = localBl.warnPrefix + plugins.clc.bold(logText);
break;
case 'log':
logText = localBl.logPrefix + plugins.clc.blue.bold(logText);
break;
default:
plugins.clc.blue.bold(logText);
console.log(('unknown logType for "' + logText + '"'));
break;
}
beautylog_console_1.beautyConsole.log(logText);
return true;
}
catch (error) {
console.log(localBl.errorPrefix
+ 'You seem to have tried logging something strange' + 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.logPrefix + 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmVhdXR5bG9nLmxvZy5oZWxwZXJzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvYmVhdXR5bG9nLmxvZy5oZWxwZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwrQ0FBOEM7QUFDOUMsMkRBQW1EO0FBQ25ELHlEQUE4QztBQUU5Qzs7Ozs7R0FLRztBQUNRLFFBQUEsV0FBVyxHQUFHLFV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