Skip to content

Log Formats

Outcome: you can tell GoAccess the layout of any common log, spell a layout out by hand when no preset fits, keep the settings in a config file, and catch the lines that fail.

Presets first

Web servers write a handful of standard layouts, and GoAccess names the common ones: COMBINED (the layout with referrer and user agent — nginx's combined, Apache's combined), COMMON (the older, shorter layout without them), VHOST variants for virtual-host logs, and presets for several cloud and proxy log shapes. The lab's whole guide runs on one word:

goaccess access.log --log-format=COMBINED

If you do not know your server's layout, run GoAccess with --config-dialog (the -c flag) instead: it shows samples of each preset against your first log lines and lets you pick the one that parses. That dialog needs a real terminal; the lab, working non-interactively, used the preset name directly and verified by the failed count — the method below.

Spelling it out by hand

A preset is a convenience, not magic. COMBINED spelled out is a format string plus its date and time shapes:

goaccess access.log \
  --log-format='%h %^[%d:%t %^] "%r" %s %b "%R" "%u"' \
  --date-format='%d/%b/%Y' \
  --time-format='%H:%M:%S'

The codes: %h the host address, %^ skip a field, %d the date, %t the time, %r the request line, %s the status, %b the bytes sent, %R the referrer, %u the user agent. The lab ran exactly this against its log and got the identical result — 27 total, 27 valid, 0 failed (transcript t07-log-formats.txt) — which is the proof that the preset and the spelling are the same instruction. When your server writes a custom layout (both nginx and Apache let you define one), this spelling is how you teach GoAccess to read it: one code per field, in order, with the literal characters (spaces, brackets, quotes) between them.

Keeping settings in a file

Repeating three flags is nobody's hobby. A config file holds them:

# goaccess.conf
log-format COMBINED
date-format %d/%b/%Y
time-format %H:%M:%S
goaccess access.log -p goaccess.conf

The lab's copy is goaccess-lab/goaccess.conf, verified against the same log with the same result. (Remember the system-wide default at /etc/goaccess/goaccess.conf from chapter 3 — -p with your own file is how you make a run depend on your settings, not the machine's.)

Failures: the lines that do not parse

Two failure shapes matter, and the lab met both.

A line that is not a log line at all. The lab appended one plain sentence to a copy of its log and ran with --invalid-requests:

goaccess badline.log --log-format=COMBINED \
  --invalid-requests=invalid.txt -o report.json

Result: 28 total lines, 27 valid, 1 failed — and invalid.txt contains the offending sentence, verbatim. On a real log this file is gold: truncated lines, a second program writing into the same file, the day the format changed — all of it lands here, named.

A preset that almost fits. The lab also ran COMMON against its combined log, expecting failures — and got none: 27 valid, 0 failed. GoAccess's parser tolerates the extra trailing fields rather than choking on them. The lesson cuts the other way from comfort: a wrong format does not always announce itself. The defence is chapter 4's habit — check the failed count and eyeball a panel. Had the mismatch run the other direction (a combined parser reading a log with fields missing), lines would fail outright; had a custom layout moved a field, counts would parse cleanly into the wrong panels, and only reading the output against the log would catch it.