Log4j Pattern to Regex Converter
Paste any Log4j or Logback layout pattern — like %d{yyyy-MM-dd} [%t] %-5p %c - %m%n — and get a ready-to-use regular expression with named capture groups, a Logstash Grok pattern, or a Fluentd regex. Works as a log4j pattern to regex online converter and as alog4j pattern to grok pattern converter, all in one place.
Everything runs locally: what you paste never leaves your browser.
Convert your Log4j pattern to regex
Specifiers detected
| Specifier | Field | Arg |
|---|---|---|
| %d | date | yyyy-MM-dd HH:mm:ss |
| %t | thread | — |
| %p | level | — |
| %c | logger | — |
| %m | message | — |
| %n | newline | — |
Matched fields
| Field | Value |
|---|---|
| date | 2024-03-15 14:22:07 |
| thread | main |
| level | INFO |
| logger | com.example.App |
| message | A |
Worked example
Pattern: %d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c - %m%n
Named capture groups
(?<date>[\d\-T:./ ,]+) \[(?<thread>[^\]]+)\] (?<level>TRACE|DEBUG|INFO|WARN|ERROR|FATAL) * (?<logger>[\w.$]+) - (?<message>.+?)(?:\r?\n)?
Logstash Grok (log4j pattern to grok pattern converter)
%{TIMESTAMP_ISO8601:date} [%{DATA:thread}] %{LOGLEVEL:level} %{JAVACLASS:logger} - %{GREEDYDATA:message}Fluentd regex
/^(?<date>[\d\-T:./ ,]+) \[(?<thread>[^\]]+)\] (?<level>TRACE|DEBUG|INFO|WARN|ERROR|FATAL) * (?<logger>[\w.$]+) - (?<message>.+?)(?:\r?\n)?$/
Raw positional groups
([\d\-T:./ ,]+) \[([^\]]+)\] (TRACE|DEBUG|INFO|WARN|ERROR|FATAL) * ([\w.$]+) - (.+?)(?:\r?\n)?
What this tool does
A Log4j or Logback pattern layout is a compact DSL that tells the logging framework how to format each line. When you need to parse those lines later — in Logstash, Fluentd, a custom script, or a SIEM — you need the inverse: a regular expression that extracts the same fields the pattern wrote. Writing that regex by hand is tedious and error-prone because every %d, %p, and %c must be translated to the right character class, and the surrounding literal text must be escaped.
This log4j pattern layout regex generator automates that translation. It tokenises the pattern in a single pass, maps each specifier to a named capture group, and escapes every literal character. The result is a regex you can drop straight into your parsing pipeline.
Convert Log4j layout pattern to regex — step by step
To convert log4j layout pattern to regex, the tool works through three stages:
- Tokenise. The pattern is scanned left-to-right with a single regex that recognises
%[padding][specifier][{arg}]sequences. Everything between specifiers is a literal token. - Map. Each specifier character (or multi-character alias like
msg,logger,le) is looked up in a table that records the canonical field name and a suitable character-class regex.%dbecomes(?<date>[\d\-T:./ ,]+);%pbecomes(?<level>TRACE|DEBUG|INFO|WARN|ERROR|FATAL); and so on. - Assemble. Literal tokens are regex-escaped and concatenated with the mapped groups to produce the final pattern.
Logback pattern to regex
Logback uses the same specifier syntax as Log4j 2.x, so this tool doubles as alogback pattern to regex converter. Multi-character Logback aliases —%le for level, %lo for logger, %msg for message — are all recognised and mapped to the same named groups as their single-character equivalents. A pattern copied from a logback.xml <pattern> element can be pasted here without modification.
Log4j pattern to Grok pattern
The Grok output format replaces each specifier with a Logstash Grok macro such as%{TIMESTAMP_ISO8601:date}, %{LOGLEVEL:level}, and%{GREEDYDATA:message}. Literal text is passed through unchanged. The result can be pasted directly into a Logstash grok filter or an Elastic pipeline without further editing. This makes the tool useful as alog4j pattern to grok pattern converter as well as a plain regex generator.
Using this as a log4j pattern to regex online tool
Because the entire conversion runs in your browser, this works as a fully offlinelog4j pattern to regex online tool once the page has loaded. There is no server round-trip, no rate limit, and no account required. The test-log-line feature lets you verify the generated regex against a real line from your application before you commit it to a pipeline configuration.