kibana/docs/reference
Maryam Saeidi 3d86a175d7
Extend default log pattern on server-side to include error information (#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


![image](https://github.com/user-attachments/assets/4f3ff751-84d5-4b5b-b6a9-d49f868a9606)

#### After


![image](https://github.com/user-attachments/assets/e22b8e45-1b0a-4d8c-b51d-5dfb3938da4f)


### 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:


![image](https://github.com/user-attachments/assets/d7dce9bc-7147-472d-b434-373322f41bbf)
2025-05-22 16:57:42 +02:00
..
cloud [Docs] Replace remaining occurrences of ESS (#220045) 2025-05-05 10:29:30 +00:00
commands [docs] Migrate docs from AsciiDoc to Markdown (#212558) 2025-03-04 14:56:07 +01:00
configuration-reference Extend default log pattern on server-side to include error information (#219940) 2025-05-22 16:57:42 +02:00
connectors-kibana [docs] Fix various syntax and rendering errors (#218883) 2025-05-22 10:10:07 +02:00
images [DOCS] Update CrowdStrike and SentinelOne connectors (#219887) 2025-05-08 11:34:40 -07:00
resources [DOCS] Adds Elastic Managed LLM to Kibana connectors (#220247) 2025-05-14 11:27:35 -07:00
advanced-settings.md [docs] Fix various syntax and rendering errors (#218883) 2025-05-22 10:10:07 +02:00
commands.md [docs] Migrate docs from AsciiDoc to Markdown (#212558) 2025-03-04 14:56:07 +01:00
configuration-reference.md [Docs] Replace remaining occurrences of ESS (#220045) 2025-05-05 10:29:30 +00:00
connectors-kibana.md [DOCS] Adds Elastic Managed LLM to Kibana connectors (#220247) 2025-05-14 11:27:35 -07:00
index.md [Reference] Revisit the kibana landing page (#220025) 2025-05-05 09:56:31 +00:00
kibana-accessibility-statement.md [Docs] Add Kibana Accessibility statement page (#220997) 2025-05-20 14:11:48 +00:00
kibana-audit-events.md [docs] Fix various syntax and rendering errors (#218883) 2025-05-22 10:10:07 +02:00
kibana-plugins.md [docs] Fix various syntax and rendering errors (#218883) 2025-05-22 10:10:07 +02:00
osquery-exported-fields.md Osquery: Update exported fields reference for osquery 5.15.0 (#215619) 2025-04-24 19:21:38 +00:00
osquery-manager-prebuilt-packs.md [docs] Migrate docs from AsciiDoc to Markdown (#212558) 2025-03-04 14:56:07 +01:00
toc.yml [Docs] Add Kibana Accessibility statement page (#220997) 2025-05-20 14:11:48 +00:00