2016-05-02 00:23:40 +00:00
|
|
|
"use strict";
|
2016-07-23 17:47:23 +00:00
|
|
|
const plugins = require("./beautylog.plugins");
|
|
|
|
const beautylog_console_1 = require("./beautylog.console");
|
2016-07-23 23:17:38 +00:00
|
|
|
const beautylog_remote_1 = require("./beautylog.remote");
|
2016-05-02 00:23:40 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param logText
|
|
|
|
* @param logType
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2016-07-23 23:17:38 +00:00
|
|
|
exports.internalLog = function (logType = 'normal', logText = 'empty log') {
|
2016-05-02 00:23:40 +00:00
|
|
|
switch (plugins.smartenv.getEnv().runtimeEnv) {
|
2016-10-16 00:26:43 +00:00
|
|
|
case 'node':
|
2016-07-23 23:17:38 +00:00
|
|
|
exports.logNode(logType, logText);
|
|
|
|
beautylog_remote_1.remoteLog(logType, logText);
|
2016-05-02 00:23:40 +00:00
|
|
|
break;
|
2016-10-16 00:26:43 +00:00
|
|
|
case 'browser':
|
2016-05-02 00:23:40 +00:00
|
|
|
logBrowser(logText, logType);
|
|
|
|
break;
|
|
|
|
default:
|
2016-10-16 00:26:43 +00:00
|
|
|
console.log('something is strange about the platform in which you try to use beautylog');
|
2016-05-02 00:23:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-10-16 00:26:43 +00:00
|
|
|
};
|
2017-01-21 17:40:40 +00:00
|
|
|
let coloredString = plugins.beautycolor.coloredString;
|
2016-07-23 23:17:38 +00:00
|
|
|
let localBl = {
|
2017-01-21 17:40:40 +00:00
|
|
|
dirPrefix: coloredString(' DIR ', 'white', 'blue') + ' ',
|
|
|
|
errorPrefix: coloredString(' ', 'red', 'red') + coloredString(' Error: ', 'red', 'black') + ' ',
|
2017-01-21 18:29:20 +00:00
|
|
|
infoPrefix: coloredString(' ', 'pink', 'pink') + coloredString(' INFO ', 'pink', 'black') + ' ',
|
2017-01-21 17:40:40 +00:00
|
|
|
logPrefix: coloredString(' ', 'white', 'cyan') + coloredString(' Log: ', 'cyan', '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') + ' '
|
2016-05-02 00:23:40 +00:00
|
|
|
};
|
2016-07-23 23:17:38 +00:00
|
|
|
exports.logNode = function (logType, logText) {
|
2016-05-02 00:23:40 +00:00
|
|
|
try {
|
|
|
|
switch (logType) {
|
|
|
|
case 'dir':
|
2017-01-21 17:40:40 +00:00
|
|
|
logText = localBl.dirPrefix + coloredString(logText, 'blue');
|
2016-05-02 00:23:40 +00:00
|
|
|
break;
|
|
|
|
case 'error':
|
2017-01-21 17:40:40 +00:00
|
|
|
logText = localBl.errorPrefix + coloredString(logText, 'red');
|
2016-05-02 00:23:40 +00:00
|
|
|
break;
|
|
|
|
case 'info':
|
2017-01-21 17:40:40 +00:00
|
|
|
logText = localBl.infoPrefix + coloredString(logText, 'pink');
|
2016-05-02 00:23:40 +00:00
|
|
|
break;
|
|
|
|
case 'normal':
|
2017-01-21 17:40:40 +00:00
|
|
|
logText = localBl.logPrefix + coloredString(logText, 'cyan');
|
2016-05-02 00:23:40 +00:00
|
|
|
break;
|
|
|
|
case 'ok':
|
2017-01-21 17:40:40 +00:00
|
|
|
logText = localBl.okPrefix + logText;
|
2016-05-02 00:23:40 +00:00
|
|
|
break;
|
|
|
|
case 'success':
|
2017-01-21 17:40:40 +00:00
|
|
|
logText = localBl.successPrefix + coloredString(logText, 'green');
|
2016-05-02 00:23:40 +00:00
|
|
|
break;
|
|
|
|
case 'warn':
|
2017-01-21 17:40:40 +00:00
|
|
|
logText = localBl.warnPrefix + coloredString(logText, 'orange');
|
2016-05-02 00:23:40 +00:00
|
|
|
break;
|
|
|
|
case 'log':
|
2017-01-21 17:40:40 +00:00
|
|
|
logText = localBl.logPrefix + coloredString(logText, 'cyan');
|
2016-05-02 00:23:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
2017-01-21 17:40:40 +00:00
|
|
|
coloredString(logText, 'blue');
|
2016-10-16 00:26:43 +00:00
|
|
|
console.log(('unknown logType for "' + logText + '"'));
|
2016-05-02 00:23:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-05-19 17:27:09 +00:00
|
|
|
beautylog_console_1.beautyConsole.log(logText);
|
2016-05-02 00:23:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (error) {
|
2016-10-16 00:26:43 +00:00
|
|
|
console.log(localBl.errorPrefix
|
|
|
|
+ 'You seem to have tried logging something strange' + error);
|
2016-05-02 00:23:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2016-07-23 17:47:23 +00:00
|
|
|
let logBrowser = function (logText, logType) {
|
2016-05-02 00:23:40 +00:00
|
|
|
switch (logType) {
|
|
|
|
case 'dir':
|
2017-01-21 17:40:40 +00:00
|
|
|
logText = localBl.dirPrefix + coloredString(logText, 'blue');
|
2016-05-02 00:23:40 +00:00
|
|
|
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':
|
2016-10-16 00:26:43 +00:00
|
|
|
logText = localBl.logPrefix + logText.cyan.bold;
|
2016-05-02 00:23:40 +00:00
|
|
|
break;
|
|
|
|
case 'ok':
|
2016-10-16 00:26:43 +00:00
|
|
|
console.log('%c OK: %c ' + logText, 'background:#000000;color:#8BC34A;', 'color:#000000;');
|
2016-05-02 00:23:40 +00:00
|
|
|
break;
|
|
|
|
case 'success':
|
2016-10-16 00:26:43 +00:00
|
|
|
console.log('%c Success: %c ' + logText, 'background:#8BC34A;color:#ffffff;', 'color:#8BC34A;');
|
2016-05-02 00:23:40 +00:00
|
|
|
break;
|
|
|
|
case 'warn':
|
2016-10-16 00:26:43 +00:00
|
|
|
console.log('%c Warn: %c ' + logText, 'background:#000000;color:#FB8C00;', 'color:#000000;');
|
2016-05-02 00:23:40 +00:00
|
|
|
break;
|
|
|
|
case 'log':
|
2016-10-16 00:26:43 +00:00
|
|
|
console.log('%c Log: %c ' + logText, 'background:#42A5F5;color:#ffffff', 'color:#42A5F5;');
|
2016-05-02 00:23:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log('unknown logType for "' + logText + '"');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2017-01-21 18:29:20 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmVhdXR5bG9nLmxvZy5oZWxwZXJzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvYmVhdXR5bG9nLmxvZy5oZWxwZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwrQ0FBOEM7QUFDOUMsMkRBQW1EO0FBQ25ELHlEQUE4QztBQUU5Qzs7Ozs7R0FLRztBQUNRLFFBQUEsV0FBVyxHQUFHLFVBQVUsVUFBa0IsUUFBUSxFQUFFLFVBQWtCLFdBQVc7SUFDeEYsTUFBTSxDQUFDLENBQUMsT0FBTyxDQUFDLFFBQVEsQ0FBQyxNQUFNLEVBQUUsQ0FBQyxVQUFVLENBQUMsQ0FBQyxDQUFDO1FBQzNDLEtBQUssTUFBTTtZQUNQLGVBQU8sQ0FBQyxPQUFPLEVBQUUsT0FBTyxDQUFDLENBQUE7WUFDekIsNEJBQVMsQ0FBQyxPQUFPLEVBQUUsT0FBTyxDQUFDLENBQUE7WUFDM0IsS0FBSyxDQUFBO1FBQ1QsS0FBSyxTQUFTO1lBQ1YsVUFBVSxDQUFDLE9BQU8sRUFBRSxPQUFPLENBQUMsQ0F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