allinurl / goaccess

GoAccess is a real-time web log analyzer and interactive viewer that runs in a terminal in *nix systems or through your browser.
https://goaccess.io
MIT License
17.88k stars 1.09k forks source link

Formatting help with JSON log #2084

Closed hitolonen closed 3 years ago

hitolonen commented 3 years ago

GoAccess - 1.4.6.

Hi, this is quite similar to https://github.com/allinurl/goaccess/issues/2083

I am having trouble formatting the logs which result into Format Errors - Verify your log/date/time format.

Example data:

{
   "sent_x_cache":"miss",
   "timestamp":"05/Apr/2021:15:01:26 +0000",
   "timestamp_iso8601":"2021-04-05T15:01:26+00:00",
   "status":"200",
   "http_host":"www.domain.com",
   "http_x_forwarded_for":"",
   "http_version":"HTTP/1.1",
   "remote_user":"",
   "request_type":"GET",
   "upstream_country_code":"US",
   "body_bytes_sent":"219362",
   "http_referer":"",
   "http_user_agent":"Mozilla/5.0",
   "content_type":"text/html; charset=UTF-8",
   "request_time":"0.549",
   "client_site_id":"246",
   "sent_vary":"Accept-Encoding",
   "remote_addr": "xxx.xx.xx.xx",
   "scheme":"https",
   "http_accept_language":"",
   "ssl_client_verify":"NONE",
   "sent_cache_control":"max-age=300, must-revalidate",
   "true_client_ip":"",
   "wplogin":"-",
   "tls_version":"TLSv1.2",
   "private_file":"",
   "request_url":"/xyz/"
}

I have tried the following formats:

# Set time format
time-format %H:%M:%S

# Set date format
date-format %Y-%m-%e

# Set log format
log-format %^:"%^"%^:"%U"%^:"%^"%^:"%m"%^:"%K"%^:"%u"%^:"%^"%^:"%h"%^:"%v"%^:"%^"%^:"%^"%^:"%^",%^:"%R",%^:"%^"%^:"%^"%^:"%dT%t+%^"%^:"%^"%^:"%C"%^:"%^"%^:"%^"%^:"%^"%^:"%M"%^:"%^"%^:"%T"%^:"%b"%^:"%s"

And also the one from #2083 with same results, Format Errors - Verify your log/date/time format.

Could you please review the formatting? Thank you.

allinurl commented 3 years ago

This should do it:

goaccess access.log --log-format='{"sent_x_cache":"%C", "timestamp": "%d:%t %^", "status": "%s", "http_host": "%v", "http_version": "%H", "remote_user": "%e", "request_type": "%m", "body_bytes_sent": "%b", "http_referer": "%R", "content_type": "%M", "request_time": "%T", "remote_addr": "%h", "request_url": "%U" }' --date-format=%d/%b/%Y --time-format=%T