diff --git a/docs/layouts.md b/docs/layouts.md index 4174110..9d98f09 100644 --- a/docs/layouts.md +++ b/docs/layouts.md @@ -143,10 +143,10 @@ Fields can be any of: - `%l` line number (requires `enableCallStack: true` on the category, see [configuration object](api.md)) - `%o` column postion (requires `enableCallStack: true` on the category, see [configuration object](api.md)) - `%s` call stack (requires `enableCallStack: true` on the category, see [configuration object](api.md)) -- `%M` function or method name (requires `enableCallStack: true` on the category, see [configuration object](api.md)) -- `%C` class name (requires `enableCallStack: true` on the category, see [configuration object](api.md)) -- `%A` function or method name alias (requires `enableCallStack: true` on the category, see [configuration object](api.md)) -- `%F` fully qualified caller name (requires `enableCallStack: true` on the category, see [configuration object](api.md)) +- `%C` class name (requires `enableCallStack: true` on the category, see [configuration object](api.md) and [#1316](https://github.com/log4js-node/log4js-node/pull/1316)) +- `%M` method or function name (requires `enableCallStack: true` on the category, see [configuration object](api.md) and [#1316](https://github.com/log4js-node/log4js-node/pull/1316)) +- `%A` method or function alias (requires `enableCallStack: true` on the category, see [configuration object](api.md) and [#1316](https://github.com/log4js-node/log4js-node/pull/1316)) +- `%F` fully qualified caller name (requires `enableCallStack: true` on the category, see [configuration object](api.md) and [#1316](https://github.com/log4js-node/log4js-node/pull/1316)) - `%x{}` add dynamic tokens to your log. Tokens are specified in the tokens parameter. - `%X{}` add values from the Logger context. Tokens are keys into the context values. - `%[` start a coloured block (colour will be taken from the log level, similar to `colouredLayout`) diff --git a/lib/LoggingEvent.js b/lib/LoggingEvent.js index 494da4c..1902751 100644 --- a/lib/LoggingEvent.js +++ b/lib/LoggingEvent.js @@ -23,12 +23,12 @@ class LoggingEvent { this.pid = process.pid; if (location) { - this.functionName = location.functionName; this.fileName = location.fileName; this.lineNumber = location.lineNumber; this.columnNumber = location.columnNumber; this.callStack = location.callStack; this.className = location.className; + this.functionName = location.functionName; this.functionAlias = location.functionAlias; this.callerName = location.callerName; } @@ -77,12 +77,12 @@ class LoggingEvent { return value; }); rehydratedEvent.location = { - functionName: rehydratedEvent.functionName, fileName: rehydratedEvent.fileName, lineNumber: rehydratedEvent.lineNumber, columnNumber: rehydratedEvent.columnNumber, callStack: rehydratedEvent.callStack, className: rehydratedEvent.className, + functionName: rehydratedEvent.functionName, functionAlias: rehydratedEvent.functionAlias, callerName: rehydratedEvent.callerName, }; diff --git a/lib/layouts.js b/lib/layouts.js index 2c01d96..86c6f77 100644 --- a/lib/layouts.js +++ b/lib/layouts.js @@ -109,10 +109,10 @@ function dummyLayout(loggingEvent) { * - %l line number * - %o column postion * - %s call stack - * - %M method or function name - * - %C class name - * - %A method or function name - * - %F fully qualified caller name + * - %C class name [#1316](https://github.com/log4js-node/log4js-node/pull/1316) + * - %M method or function name [#1316](https://github.com/log4js-node/log4js-node/pull/1316) + * - %A method or function alias [#1316](https://github.com/log4js-node/log4js-node/pull/1316) + * - %F fully qualified caller name [#1316](https://github.com/log4js-node/log4js-node/pull/1316) * - %x{} add dynamic tokens to your log. Tokens are specified in the tokens parameter * - %X{} add dynamic tokens to your log. Tokens are specified in logger context * You can use %[ and %] to define a colored block. @@ -134,7 +134,7 @@ function dummyLayout(loggingEvent) { */ function patternLayout(pattern, tokens) { const TTCC_CONVERSION_PATTERN = '%r %p %c - %m%n'; - const regex = /%(-?[0-9]+)?(\.?-?[0-9]+)?([[\]cdhmnprzxXyflosMCAF%])(\{([^}]+)\})?|([^%]+)/; + const regex = /%(-?[0-9]+)?(\.?-?[0-9]+)?([[\]cdhmnprzxXyflosCMAF%])(\{([^}]+)\})?|([^%]+)/; pattern = pattern || TTCC_CONVERSION_PATTERN; @@ -326,14 +326,14 @@ function patternLayout(pattern, tokens) { return loggingEvent.callStack || ''; } - function functionName(loggingEvent) { - return loggingEvent.functionName || ''; - } - function className(loggingEvent) { return loggingEvent.className || ''; } + function functionName(loggingEvent) { + return loggingEvent.functionName || ''; + } + function functionAlias(loggingEvent) { return loggingEvent.functionAlias || ''; } @@ -361,8 +361,8 @@ function patternLayout(pattern, tokens) { l: lineNumber, o: columnNumber, s: callStack, - M: functionName, C: className, + M: functionName, A: functionAlias, F: callerName, }; diff --git a/lib/logger.js b/lib/logger.js index 9291e6e..ca253b2 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -31,12 +31,12 @@ function defaultParseCallStack(data, skipIdx = 4) { } return { - functionName, fileName: lineMatch[2], lineNumber: parseInt(lineMatch[3], 10), columnNumber: parseInt(lineMatch[4], 10), callStack: stacklines.join('\n'), className, + functionName, functionAlias, callerName: lineMatch[1] || '', }; diff --git a/test/tap/LoggingEvent-test.js b/test/tap/LoggingEvent-test.js index ec4df9f..2ec6c6c 100644 --- a/test/tap/LoggingEvent-test.js +++ b/test/tap/LoggingEvent-test.js @@ -74,12 +74,12 @@ test('LoggingEvent', (batch) => { const functionAlias = ''; const callerName = ''; const location = { - functionName, fileName, lineNumber, columnNumber, callStack, className, + functionName, functionAlias, callerName, }; @@ -90,12 +90,12 @@ test('LoggingEvent', (batch) => { { user: 'bob' }, location ); - t.equal(event.functionName, functionName); t.equal(event.fileName, fileName); t.equal(event.lineNumber, lineNumber); t.equal(event.columnNumber, columnNumber); t.equal(event.callStack, callStack); t.equal(event.className, className); + t.equal(event.functionName, functionName); t.equal(event.functionAlias, functionAlias); t.equal(event.callerName, callerName); @@ -106,8 +106,8 @@ test('LoggingEvent', (batch) => { t.equal(event2.lineNumber, undefined); t.equal(event2.columnNumber, undefined); t.equal(event2.callStack, undefined); - t.equal(event2.functionName, undefined); t.equal(event2.className, undefined); + t.equal(event2.functionName, undefined); t.equal(event2.functionAlias, undefined); t.equal(event2.callerName, undefined); t.end(); @@ -125,12 +125,12 @@ test('LoggingEvent', (batch) => { const functionAlias = 'baz'; const callerName = 'Foo.bar [as baz]'; const location = { - functionName, fileName, lineNumber, columnNumber, callStack, className, + functionName, functionAlias, callerName, }; @@ -141,12 +141,12 @@ test('LoggingEvent', (batch) => { { user: 'bob' }, location ); - t.equal(event.functionName, functionName); t.equal(event.fileName, fileName); t.equal(event.lineNumber, lineNumber); t.equal(event.columnNumber, columnNumber); t.equal(event.callStack, callStack); t.equal(event.className, className); + t.equal(event.functionName, functionName); t.equal(event.functionAlias, functionAlias); t.equal(event.callerName, callerName); t.end();