stack with line breaks

parent 7a4058b0
......@@ -9,6 +9,8 @@ if (!('toJSON' in Error.prototype))
Object.getOwnPropertyNames(this).forEach(function (key) {
alt[key] = this[key];
if (key === 'stack')
alt[key] = alt[key].split('\n');
}, this);
return alt;
......@@ -21,6 +23,15 @@ const fs = require('fs');
const path = require('path');
const logger = {
_makeString : function(args) {
let string = '';
for (var i = 0; i < args.length; i++) {
string += JSON.stringify(args[i], "", 4) + ' ';
}
return string;
},
_console : function (string) {
if (this._loggers.indexOf(this.CONSOLE) >= 0) {
console.log(string);
......@@ -39,12 +50,7 @@ const logger = {
},
debug : function () {
let string = '';
for (var i = 0; i < arguments.length; i++) {
string += JSON.stringify(arguments[i]) + ' ';
}
let str = this._prefix + '\033[34m Debug: \033[30m' + string;
let str = this._prefix + '\033[34m Debug: \033[30m' + this._makeString(arguments);
if (this._level >= this.DEBUG) {
this._console(str);
this._file(str);
......@@ -52,12 +58,7 @@ const logger = {
}
},
info : function () {
let string = '';
for (var i = 0; i < arguments.length; i++) {
string += JSON.stringify(arguments[i]) + ' ';
}
let str = this._prefix + '\033[32m Info: \033[30m' + string;
let str = this._prefix + '\033[32m Info: \033[30m' + this._makeString(arguments);
if (this._level >= this.INFO) {
this._console(str);
this._file(str);
......@@ -65,12 +66,7 @@ const logger = {
}
},
warning : function () {
let string = '';
for (var i = 0; i < arguments.length; i++) {
string += JSON.stringify(arguments[i]) + ' ';
}
let str = this._prefix + '\033[33m Warning: \033[30m' + string;
let str = this._prefix + '\033[33m Warning: \033[30m' + this._makeString(arguments);
if (this._level >= this.WARNING) {
this._console(str);
this._file(str);
......@@ -78,12 +74,7 @@ const logger = {
}
},
error : function () {
let string = '';
for (var i = 0; i < arguments.length; i++) {
string += JSON.stringify(arguments[i]) + ' ';
}
let str = this._prefix + '\033[31m Error: \033[30m' + string;
let str = this._prefix + '\033[31m Error: \033[30m' + this._makeString(arguments);
if (this._level >= this.ERROR) {
this._console(str);
this._file(str);
......@@ -91,12 +82,7 @@ const logger = {
}
},
fatal : function () {
let string = '';
for (var i = 0; i < arguments.length; i++) {
string += JSON.stringify(arguments[i]) + ' ';
}
let str = this._prefix + '\033[35m Fatal: \033[30m' + string;
let str = this._prefix + '\033[35m Fatal: \033[30m' + this._makeString(arguments);
if (this._level >= this.FATAL) {
this._console(str);
this._file(str);
......
{
"name": "nodejs-logger",
"version": "1.1.0",
"version": "1.1.1",
"description": "Logger for mirera node-js server",
"main": "index.js",
"scripts": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment