Comparing version 0.0.9 to 0.0.11
60
index.js
@@ -157,2 +157,3 @@ /* eslint-disable class-methods-use-this */ | ||
this.process_debug = !!process.env.DEBUG; | ||
this._lastLogMessage = null; | ||
} | ||
@@ -221,7 +222,10 @@ | ||
console.dir(msg); | ||
this._lastLogMessage = msg; | ||
} else { | ||
console.log(`${color}${this.UnderlineOff}${prefix}${color}${msg}${this.reset}`); | ||
const logMessage = `${color}${this.UnderlineOff}${prefix}${color}${msg}${this.reset}`; | ||
console.log(logMessage); | ||
this._lastLogMessage = logMessage; | ||
} | ||
if (logger) { | ||
logger.info(`${prefix}${msg.replace(/\[\d+m/g, '')}`); | ||
logger.info(`${prefix}${msg.replace(/\[(\d+;)?\d+m/g, '')}`); | ||
} | ||
@@ -294,3 +298,3 @@ } | ||
/** | ||
* Удаляет ESC-gjcktljdfntkmyjcnb bp cnhjrb (для записи в лог) | ||
* Удаляет ESC-последовательности из строки (для записи в лог) | ||
* @param {String} str | ||
@@ -376,4 +380,7 @@ * @returns {String} | ||
console.dir(msg); | ||
this._lastLogMessage = msg; | ||
} else { | ||
console.log(`${lb}${color}${this.UnderlineOff}${prefix}${color}${cTitle}${this.UnderlineOff}${color}${msg}${this.reset}`); | ||
const logMessage = `${lb}${color}${this.UnderlineOff}${prefix}${color}${cTitle}${this.UnderlineOff}${color}${msg}${this.reset}`; | ||
console.log(logMessage); | ||
this._lastLogMessage = logMessage; | ||
} | ||
@@ -529,3 +536,4 @@ if (logger) { | ||
stack = stack.trim(); | ||
const stackArr = stack.split(/[\r\n]+/).filter((v) => !!v.trim()); | ||
const stackArr = stack.split(/[\r\n]+/) | ||
.filter((v) => !!v.trim()); | ||
if (stackArr.length < 2) { | ||
@@ -536,3 +544,4 @@ return; | ||
const t = this; | ||
const stackArr2 = stackArr.map(t.getCallStackFrameObj).filter((v) => !!v); | ||
const stackArr2 = stackArr.map(t.getCallStackFrameObj) | ||
.filter((v) => !!v); | ||
return [{ line }, ...stackArr2]; | ||
@@ -557,3 +566,4 @@ } | ||
return ` at ${frame.func || '<>'} (${frame.file || ''}:${frame.row || 0}:${frame.col || 0})`.replace(' (:0:0)', ''); | ||
}).join('\n'); | ||
}) | ||
.join('\n'); | ||
} | ||
@@ -609,3 +619,12 @@ | ||
const { lb = 0, nc, msg, thr, errorLogger, prefix, noStack = false, socket } = options; | ||
const { | ||
lb = 0, | ||
nc, | ||
msg, | ||
thr, | ||
errorLogger, | ||
prefix, | ||
noStack = false, | ||
socket | ||
} = options; | ||
@@ -700,6 +719,29 @@ let targetFrame; | ||
g (msg) { | ||
this.echo(msg, { colorNum: this.Green, bold: true }); | ||
this.echo(msg, { | ||
colorNum: this.Green, | ||
bold: true | ||
}); | ||
} | ||
getSilly ({ debugIDs, prefix = 'SILLY' }) { | ||
const { colorBlue: cB, colorLBlue: cLB, colorCyan: cC, colorGreen: cG, colorMagenta: cM } = this; | ||
if (debugIDs && typeof debugIDs === 'string') { | ||
debugIDs = [debugIDs]; | ||
} else if (!Array.isArray(debugIDs)) { | ||
debugIDs = []; | ||
} | ||
const isSilly = this.isLevelAllowed('silly') || [...debugIDs, '*'].some((v) => process.env.DEBUG === v); | ||
return (msg) => { | ||
if (!isSilly) { | ||
return; | ||
} | ||
if (typeof msg === 'object') { | ||
msg = Object.entries(msg).map(({ name, value }) => `${cC}${name}${cLB}=${cG}${typeof value === 'object' ? JSON.stringify(value) : value}`).join(`${cB}&${cG}`); | ||
} | ||
const pfx = `${cM}[${prefix}]${cG}`; | ||
this.info(pfx, msg); | ||
}; | ||
} | ||
} | ||
module.exports = new Echo(); |
{ | ||
"name": "af-echo", | ||
"version": "0.0.9", | ||
"version": "0.0.11", | ||
"description": "A highly specialized function library", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26377
677
4