Fixed it!!
This commit is contained in:
parent
de3e95c383
commit
9e38f0b3e3
2 changed files with 20 additions and 6 deletions
|
@ -66,15 +66,29 @@ class Logger {
|
||||||
let argPlaceholder = this.argsPlaceholder;
|
let argPlaceholder = this.argsPlaceholder;
|
||||||
let matches = (msg.match(new RegExp(argPlaceholder, "g")) || []).length;
|
let matches = (msg.match(new RegExp(argPlaceholder, "g")) || []).length;
|
||||||
let argsFilled = 0;
|
let argsFilled = 0;
|
||||||
args.forEach((v, i, a) => {
|
// args.forEach((v, i, a) => {
|
||||||
|
// if (Buffer.isBuffer(v))
|
||||||
|
// v = conversion.properHex(v).str;
|
||||||
|
// if (typeof v === 'object')
|
||||||
|
// v = "\x1b[0m" + JSON.stringify(v, null, 2) + "\x1b[0m";
|
||||||
|
|
||||||
|
// msg = msg.replace(argPlaceholder, v);
|
||||||
|
// argsFilled++;
|
||||||
|
// console.log(`${argPlaceholder} -> ${v}`);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// regexp replace
|
||||||
|
let regexp = new RegExp(argPlaceholder, "g");
|
||||||
|
msg = msg.replace(regexp, (match, offset, string) => {
|
||||||
|
if (argsFilled >= matches)
|
||||||
|
return match;
|
||||||
|
let v = args[argsFilled];
|
||||||
if (Buffer.isBuffer(v))
|
if (Buffer.isBuffer(v))
|
||||||
v = conversion.properHex(v).str;
|
v = conversion.properHex(v).str;
|
||||||
if (typeof v === 'object')
|
if (typeof v === 'object')
|
||||||
v = "\x1b[0m" + JSON.stringify(v, null, 2) + "\x1b[0m";
|
v = "\x1b[0m" + JSON.stringify(v, null, 2) + "\x1b[0m";
|
||||||
|
|
||||||
msg = msg.replace(argPlaceholder, v);
|
|
||||||
argsFilled++;
|
argsFilled++;
|
||||||
console.log(`${argPlaceholder} -> ${v}`);
|
return v;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (matches !== argsFilled && args.length >= matches)
|
if (matches !== argsFilled && args.length >= matches)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "logger4njs",
|
"name": "logger4njs",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"description": "Logger for Node JS",
|
"description": "Logger for Node JS",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"directories": {
|
"directories": {
|
||||||
|
|
Reference in a new issue