# Multi-line logs in Wazuh: multi-line and multiline_regex

> Localfile setup for multi-line logs in Wazuh: multi-line with a fixed line count, multiline_regex with match, replace and timeout, plus ignore and restrict.

Published: 2026-11-12. Category: Configuration. Tags: Wazuh 4. URL: https://wazuh.blog/en/blog/wazuh-localfile-multiline/ Polish original: https://wazuh.blog/blog/wazuh-localfile-multiline/

An application entry that spans several lines, for example a Python Traceback, needs a `<localfile>` setting that tells the agent where one event ends. The Wazuh documentation describes two formats for this: `multi-line` for a fixed number of lines and `multi-line-regex` for a variable number of lines, driven by the `multiline_regex` option.

## Log formats and multiple lines

The `<localfile>` block configures data collection from files, Windows events and command output. The documentation lists these options for it: `location`, `command`, `alias`, `frequency`, `only-future-events`, `query`, `label`, `target`, `log_format`, `out_format`, `ignore_binaries`, `age`, `exclude`, `reconnect_time`, `multiline_regex`, `ignore`, `restrict` and `filter`. Whether several lines of a file become one event is decided by `log_format`.

| Format | Description in the documentation | Multiple lines |
| --- | --- | --- |
| `syslog` | Text in a syslog-like format, one entry per line | One entry per line |
| `json` | JSON files written on a single line | Single-line JSON |
| `multi-line` | Applications that write a fixed number of lines per event | Joins lines until the count is reached |
| `multi-line-regex` | Applications with a variable number of lines per event | Behavior depends on `multiline_regex` |
| `mysql_log` | MySQL logs | Does not support multi-line logs |
| `postgresql_log` | PostgreSQL logs | Does not support multi-line logs |

## Fixed number of lines: `multi-line`

The documentation describes the `multi-line` format as intended for applications that write several fixed lines per event. The syntax is `multi-line: <NUMBER>`, and the agent joins lines until it reaches the given number.

```xml
<localfile>
  <!-- Every event in this example file has exactly five lines -->
  <log_format>multi-line: 5</log_format>
  <location>/var/log/example-app/app.log</location>
</localfile>
```

The documentation shows a sample of five lines with the same timestamp and host name, and its form after processing by `wazuh-analysisd`. The original lines are joined with spaces into one line. The same shape on synthetic data:

```text
Nov 12 10:15:01 agent-01 example-app: step one
Nov 12 10:15:01 agent-01 example-app: step two
Nov 12 10:15:01 agent-01 example-app: step three
Nov 12 10:15:01 agent-01 example-app: step four
Nov 12 10:15:01 agent-01 example-app: step five
```

After joining, `wazuh-analysisd` receives one line:

```text
Nov 12 10:15:01 agent-01 example-app: step one Nov 12 10:15:01 agent-01 example-app: step two Nov 12 10:15:01 agent-01 example-app: step three Nov 12 10:15:01 agent-01 example-app: step four Nov 12 10:15:01 agent-01 example-app: step five
```

## Variable number of lines: `multiline_regex`

The `multiline_regex` option sets the regular expression, the match criterion and the way line endings are handled for logs with a variable number of lines. The value is any PCRE2 expression. The option works only when `log_format` has the value `multi-line-regex`.

| Attribute | Allowed values | Default | Description in the documentation |
| --- | --- | --- | --- |
| `match` | `start`, `end`, `all` | `start` | How the match is treated |
| `replace` | `no-replace`, `wspace`, `tab`, `none` | `no-replace` | Replacing or removing the line ending |
| `timeout` | From 1 to 120 | `5` | Maximum time to wait for a new line, in seconds |

The meaning of the `match` values according to the documentation:

- `start` groups as one event the content between two lines that match the expression. The grouped event does not contain the last matching line.
- `end` groups the content up to the line that matches the expression.
- `all` groups the content until the whole event matches the expression.

For `start` and `end` the expression is matched against a single line. So with `start` a line that matches the pattern opens a new event. With `end` a line that matches the pattern closes the current one.

## `timeout` and `age`

The value of the `timeout` attribute cannot be greater than the value of the `age` option. The `age` option makes the agent read only files modified within the given period. Example from the documentation: with `age` equal to `1d`, files not modified for one day are skipped. The value is a positive number with the unit `s`, `m`, `h` or `d`, and the default value is `n/a`.

```xml
<localfile>
  <log_format>multi-line-regex</log_format>
  <location>/var/log/example-app/*.log</location>
  <!-- Skip files not modified during the last day -->
  <age>1d</age>
  <multiline_regex replace="wspace" timeout="30">^Traceback</multiline_regex>
</localfile>
```

## Python Traceback as a pattern

The documentation shows a configuration in which a Python Traceback is read as one log and newline characters are replaced with spaces. Below is the same syntax.

```xml
<localfile>
  <log_format>multi-line-regex</log_format>
  <location>/var/log/example-app/app.log</location>
  <!-- Each event starts at a line beginning with "Traceback" -->
  <multiline_regex replace="wspace">^Traceback</multiline_regex>
</localfile>
```

The configuration sets neither `match` nor `timeout`, so the defaults apply: `start` and 5 seconds. An example input shape:

```text
Traceback (most recent call last):
  File "example-app.py", line 12, in run
    example_call()
RuntimeError: example failure
```

With `match="start"` the expression `^Traceback` marks the start of the event, and `replace="wspace"` makes the line endings in the group be replaced with spaces.

If an entry ends with a predictable line instead of starting with one, the same block can use `match="end"`. The attributes and their values come from the table above.

```xml
<localfile>
  <log_format>multi-line-regex</log_format>
  <location>/var/log/example-app/batch.log</location>
  <!-- Each event ends at a line beginning with "END-OF-RECORD" -->
  <multiline_regex match="end" replace="wspace" timeout="10">^END-OF-RECORD</multiline_regex>
</localfile>
```

## Choosing files: `exclude` and `only-future-events`

When `location` uses a wildcard, the `exclude` option points to a group of files the agent should skip. The documentation gives an example in which all files of a directory are read except those whose name starts with `e`. The option accepts any log file or wildcard pattern, and its default value is `n/a`. The same syntax for an application directory:

```xml
<localfile>
  <log_format>multi-line-regex</log_format>
  <location>/var/log/example-app/*.log</location>
  <!-- Skip files whose names start with "debug" -->
  <exclude>/var/log/example-app/debug*</exclude>
  <multiline_regex replace="wspace">^Traceback</multiline_regex>
</localfile>
```

The `only-future-events` option decides from which point `wazuh-logcollector` reads the file after it starts. By default it is `yes`, and the process reads logs generated since startup. The value `no` makes it also collect events written while `wazuh-logcollector` was stopped. The `max-size` attribute then lets you skip old events if their length since the last read exceeds the given value in bytes.

| Element | Values | Default |
| --- | --- | --- |
| `only-future-events` | `yes` or `no` | `yes` |
| Attribute `max-size` | From 0 to 2GB, units `B`, `KB`, `MB`, `GB` | `10MB` |

## Filtering a whole group: `ignore` and `restrict`

`ignore` points to an expression whose match causes the entry to be skipped. With several `ignore` elements, a match with any of them is enough. `restrict` works the other way round: with several elements the entry is processed only if it matches all of them.

| Option | Several expressions | Effect of a match | Attribute `type` |
| --- | --- | --- | --- |
| `ignore` | Any one is enough | Entry skipped | `osregex`, `osmatch`, `PCRE2` (default `PCRE2`) |
| `restrict` | All required | Entry processed | `osregex`, `osmatch`, `PCRE2` (default `PCRE2`) |

For formats that group multiple lines, the whole group is treated as one log when the expression is evaluated. When the same entry matches both `ignore` and `restrict` in the same `localfile` block, it is dropped, because `ignore` takes precedence. The `ignore` and `restrict` filters do not apply to the `eventchannel` format, which has its own filtering through queries.

The documentation example skips audit events about configuration changes and shows two expression types in one block:

```xml
<localfile>
  <log_format>audit</log_format>
  <location>/var/log/audit/audit.log</location>
  <ignore type="PCRE2">type=.+_CHANGE</ignore>
  <ignore type="osregex">type=CONFIG_\.+</ignore>
</localfile>
```

The documentation example for `restrict` processes only syslog events related to a specific user name and also combines two expression types:

```xml
<localfile>
  <log_format>syslog</log_format>
  <location>/custom/file/path</location>
  <restrict type="PCRE2">username_\d?</restrict>
  <restrict type="osregex">Jun\.+</restrict>
</localfile>
```

In a `multi-line-regex` block the `ignore` filter evaluates the whole Traceback as one log, so a match skips the whole group:

```xml
<localfile>
  <log_format>multi-line-regex</log_format>
  <location>/var/log/example-app/app.log</location>
  <multiline_regex replace="wspace">^Traceback</multiline_regex>
  <!-- Drop whole tracebacks raised by the synthetic health probe -->
  <ignore type="PCRE2">example_healthcheck</ignore>
</localfile>
```

## Testing

`wazuh-logtest` (`/var/ossec/bin/wazuh-logtest`) processes only single-line logs, without newline characters. The tool itself is described in the article on [wazuh-logtest](/en/blog/wazuh-logtest/), and writing decoders for such lines in the article on [custom decoders](/en/blog/wazuh-custom-decoders/).

## What the documentation does not specify

The documentation does not define the exact character for `replace="tab"`, `replace="none"` and `replace="no-replace"`, nor whether `match="all"` evaluates the text before or after line endings are replaced. It does not describe the behavior of `multi-line` when fewer lines arrive than the given number, nor the fate of an incomplete group after `timeout` expires. It gives no maximum length of a grouped event. It does not describe a procedure that checks grouping from the file to the alert.

## Sources

- https://documentation.wazuh.com/current/user-manual/reference/ossec-conf/localfile.html
- https://documentation.wazuh.com/current/user-manual/ruleset/index.html
