[8.19] Extend default log pattern on server-side to include error information (#219940)#221339
Merged
maryam-saeidi merged 1 commit intoelastic:8.19from May 23, 2025
Merged
Conversation
elastic#219940) ## Release Notes Kibana logging's pattern layout, used by default for the console appender, will now use a new default pattern layout `[%date][%level][%logger] %message %error`. This will include the error name and stack trace if these were included in the log entry. To opt out of this behavior users can omit the `%error` placeholder from their log pattern config in kibana.yml e.g.: ``` logging: appenders: console: type: console layout: type: pattern pattern: "[%date][%level][%logger] %message" ``` ## Summary Previously, when we pass the error in meta, the information related to stacktrace and error message was not available in console. This PR changed the default pattern to also include error information if it is provided in meta (similar to the way that the logging happens when error is directly passed to logger.error). New pattern: (added `%error` at the end) ``` [%date][%level][%logger] %message %error ``` Here you can see the difference: Logger: ``` server.logger.error( `Unable to create Synthetics monitor ${monitorWithNamespace[ConfigKey.NAME]}`, { error: e } ); ``` #### Before  #### After  ### Alternative We could also change the MetaConversion and include this information, but we might have additional meta information which I am not sure if it is OK to be logged by default. Let me know if you prefer changing MetaConversion instead of adding a new error conversion. <details> <summary>Code changes for MetaConversion</summary> ``` function isError(x: any): x is Error { return x instanceof Error; } export const MetaConversion: Conversion = { pattern: /%meta/g, convert(record: LogRecord) { if (!record.meta) { return ''; } const { error, ...rest } = record.meta; const metaString = Object.keys(rest).length !== 0 ? JSON.stringify(rest) : ''; let errorString = ''; if (isError(record.meta?.error)) { errorString = record.meta?.error.stack || ''; } return [metaString, errorString].filter(Boolean).join(' '); }, }; ``` </details> Here is how adjusting meta will look like in this case:  (cherry picked from commit 3d86a17) # Conflicts: # docs/reference/configuration-reference/logging-settings.md
Contributor
|
A documentation preview will be available soon. Request a new doc build by commenting
If your PR continues to fail for an unknown reason, the doc build pipeline may be broken. Elastic employees can check the pipeline status here. |
cesco-f
approved these changes
May 23, 2025
Contributor
💚 Build Succeeded
Metrics [docs]Module Count
Public APIs missing comments
Page load bundle
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport
This will backport the following commits from
mainto8.19:Questions ?
Please refer to the Backport tool documentation