Skip to content
← All guides

Find errors in Java logs across servers

Java applications using Log4j or Logback write lines like this:

2026-07-06 12:21:37,393 ERROR com.app.orders.OrderService [http-nio-8080-exec-302] Order 88412 rolled back: upstream returned 503

Each line has the same parts: timestamp, level, logger, thread, message. Using that structure is the fastest way to find the cause of an incident.

Quick searches with grep

All errors and warnings:

grep -nE " (ERROR|WARN) " /var/log/app/app.log

Every exception, with the stack trace after it:

grep -n -A 30 "Exception" /var/log/app/app.log

Everything one request thread did, which shows what led up to an error:

grep -n "\[http-nio-8080-exec-302\]" /var/log/app/app.log

One component only:

grep -n "com.app.orders" /var/log/app/app.log

Across several servers, run the same command over SSH for each host (see grep logs over SSH).

Follow one thread across the error

The error line is rarely the cause. The useful pattern is:

  1. Find the ERROR line and note its thread (exec-302) and time.
  2. Search that thread in a few minutes' window before the error.
  3. Read the sequence: the request, the slow call, the retry, then the failure.

With grep that means two or three searches per server, and merging the output by time yourself.

Turn each line into columns

A regex with one capturing group per field splits the line into columns:

^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3})\s+([A-Z]+)\s+([\w\.]+)\s+(\[.*?\])\s+(.*)$
GroupColumn
1timestamp (format yyyy-MM-dd HH:mm:ss,SSS)
2level
3logger
4thread
5message

In Logswarm you save this pattern once and assign it to your log directories. Every search then shows results as a table sorted by timestamp across all servers. You can:

  • set level = ERROR || WARN and thread = 302 in Complex mode, so only matching lines are fetched from the servers;
  • filter the downloaded results by level, logger or thread without searching again;
  • show 20 lines of context after each match to read stack traces.

The regex guide has this pattern and an Nginx example ready to copy.

Related