ng2-logger
Version:
isomorphic logger for browser/server in typescript
62 lines • 2.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const level_1 = require("./level");
const helper_1 = require("./helper");
const backend_logging_1 = require("./backend-logging");
if (helper_1.isNode) {
//#region backend
var chalk = require('chalk');
var path = require('path');
//#endregion
}
class Display {
static msg(message, params, moduleName, moduleColor, level, moduleWidth) {
let color = 'gray';
if (level === level_1.Level.INFO)
color = 'deepskyblue';
if (level === level_1.Level.ERROR)
color = 'red';
if (level === level_1.Level.WARN)
color = 'orange';
if (moduleWidth) {
const diff = moduleWidth - moduleName.length;
if (diff > 0) {
for (let i = 0; i < diff; i++) {
moduleName += ' ';
}
}
}
if (helper_1.isBrowser) {
if (typeof message === 'string') {
let a1 = '%c ' + moduleName + ' %c ' + message + ' ';
let a2 = 'background: ' + moduleColor + ';color:white; border: 1px solid ' + moduleColor + '; ';
let a3 = 'border: 1px solid ' + color + '; ';
params.unshift(a3);
params.unshift(a2);
params.unshift(a1);
}
else {
let a1 = '%c ' + moduleName + ' ';
let a2 = 'background: ' + moduleColor + ';color:white; border: 1px solid ' + color + '; ';
params.push(message);
params.unshift(a2);
params.unshift(a1);
}
console.log.apply(console, params);
}
if (helper_1.isNode) {
let a1 = chalk.bgHex(moduleColor)(chalk.black(moduleName));
let p = params;
if (typeof message === 'string') {
a1 = a1 + chalk.keyword(color)(' [') + chalk.dim(message) + chalk.keyword(color)('] ');
}
else {
p = [message].concat(params);
}
backend_logging_1.consoleLog(a1, level);
backend_logging_1.displayParams(p, level);
}
}
}
exports.Display = Display;
//# sourceMappingURL=display.js.map