smartlog-destination-local/dist/beautylog.log.helpers.js

110 lines
9.5 KiB
JavaScript

"use strict";
const plugins = require("./beautylog.plugins");
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 coloredString = plugins.beautycolor.coloredString;
let localBl = {
dirPrefix: coloredString(' DIR ', 'white', 'blue') + ' ',
errorPrefix: coloredString(' ', 'red', 'red') + coloredString(' ERROR! ', 'red', 'black') + ' ',
infoPrefix: coloredString(' ', 'blue', 'blue') + coloredString(' INFO: ', 'blue', 'black') + ' ',
logPrefix: coloredString(' ', 'white', 'cyan') + coloredString(' LOG: ', 'cyan', 'black') + ' ',
notePrefix: coloredString(' ', 'pink', 'pink') + coloredString(' NOTE -> ', 'pink', 'black') + ' ',
okPrefix: coloredString(' ', 'green', 'green') + coloredString(' OK! ', 'green', 'black') + ' ',
successPrefix: coloredString(' ', 'green', 'green') + coloredString(' SUCCESS! ', 'green', 'black') + ' ',
warnPrefix: coloredString(' ', 'orange', 'orange') + coloredString(' WARN: -> ', 'orange', 'black') + ' '
};
exports.logNode = function (logType, logText) {
try {
switch (logType) {
case 'dir':
logText = localBl.dirPrefix + coloredString(logText, 'blue');
break;
case 'error':
logText = localBl.errorPrefix + coloredString(logText, 'red');
break;
case 'info':
logText = localBl.infoPrefix + coloredString(logText, 'blue');
break;
case 'normal':
logText = localBl.logPrefix + coloredString(logText, 'cyan');
break;
case 'note':
logText = localBl.notePrefix + coloredString(logText, 'pink');
break;
case 'ok':
logText = localBl.okPrefix + coloredString(logText, 'green');
break;
case 'success':
logText = localBl.successPrefix + coloredString(logText, 'green');
break;
case 'warn':
logText = localBl.warnPrefix + coloredString(logText, 'orange');
break;
case 'log':
logText = localBl.logPrefix + coloredString(logText, 'cyan');
break;
default:
coloredString(logText, 'blue');
console.log(('unknown logType for "' + logText + '"'));
break;
}
console.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 + coloredString(logText, 'blue');
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmVhdXR5bG9nLmxvZy5oZWxwZXJzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvYmVhdXR5bG9nLmxvZy5oZWxwZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwrQ0FBOEM7QUFDOUMseURBQThDO0FBRTlDOzs7OztHQUtHO0FBQ1EsUUFBQSxXQUFXLEdBQUcsVUFBVSxVQUFrQixRQUFRLEVBQUUsVUFBa0IsV0FBVztJQUN4RixNQUFNLENBQUMsQ0FBQyxPQUFPLENBQUMsUUFBUSxDQUFDLE1BQU0sRUFBRSxDQUFDLFVBQVUsQ0FBQyxDQUFDLENBQUM7UUFDM0MsS0FBSyx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