mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
feat: allow setting how deeply a logger should search into the stack
`logger.callStackLinesToSkip = 2` will make it skip 2 extra lines above the base. You can't skip negative lines Refs: #1268
This commit is contained in:
parent
89b8a58f3f
commit
a17c8e5e6f
@ -94,6 +94,8 @@ class Logger {
|
||||
this.category = name;
|
||||
this.context = {};
|
||||
/** @private */
|
||||
this.callStackSkipIndex = 0;
|
||||
/** @private */
|
||||
this.parseCallStack = defaultParseCallStack;
|
||||
debug(`Logger created (${this.category}, ${this.level})`);
|
||||
}
|
||||
@ -120,6 +122,20 @@ class Logger {
|
||||
categories.setEnableCallStackForCategory(this.category, bool === true);
|
||||
}
|
||||
|
||||
get callStackLinesToSkip() {
|
||||
return this.callStackSkipIndex;
|
||||
}
|
||||
|
||||
set callStackLinesToSkip(number) {
|
||||
if (typeof number !== 'number') {
|
||||
throw new TypeError('Must be a number');
|
||||
}
|
||||
if (number < 0) {
|
||||
throw new RangeError('Must be >= 0');
|
||||
}
|
||||
this.callStackSkipIndex = number;
|
||||
}
|
||||
|
||||
log(level, ...args) {
|
||||
const logLevel = levels.getLevel(level);
|
||||
if (!logLevel) {
|
||||
@ -150,7 +166,10 @@ class Logger {
|
||||
if (this.useCallStack) {
|
||||
try {
|
||||
if (data[0] instanceof Error) {
|
||||
callStack = this.parseCallStack(data[0], baseCallStackSkip);
|
||||
callStack = this.parseCallStack(
|
||||
data[0],
|
||||
this.callStackSkipIndex + baseCallStackSkip
|
||||
);
|
||||
}
|
||||
} catch (_err) {
|
||||
// Ignore Error
|
||||
@ -159,7 +178,9 @@ class Logger {
|
||||
callStack ||
|
||||
this.parseCallStack(
|
||||
new Error(),
|
||||
defaultErrorCallStackSkip + baseCallStackSkip
|
||||
this.callStackSkipIndex +
|
||||
defaultErrorCallStackSkip +
|
||||
baseCallStackSkip
|
||||
);
|
||||
}
|
||||
const loggingEvent = new LoggingEvent(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user