Skip to content

Commit

Permalink
Merge pull request #2607 from SlowMo24/traefik-clf
Browse files Browse the repository at this point in the history
feat(settings): add traefik log format
  • Loading branch information
allinurl committed Jan 9, 2024
2 parents 57bfa03 + 15c9b62 commit 01c074a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- Added support for Traefik log format

Changes to GoAccess 1.8.1 - Tuesday, October 31, 2023

- Added latest Android and macOS versions to the list of OSs.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ not limited to:
* Squid Native Format.
* W3C format (IIS).
* Caddy's JSON Structured format.
* Traefik's CLF flavor

## Why GoAccess? ##
GoAccess was designed to be a fast, terminal-based log analyzer. Its core idea
Expand Down
4 changes: 4 additions & 0 deletions config/goaccess.conf
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
# CADDY JSON Structured
#log-format {"ts":"%x.%^","request":{"remote_ip":"%h","proto":"%H","method":"%m","host":"%v","uri":"%U","headers":{"User-Agent":["%u","%^"]},"tls":{"cipher_suite":"%k","proto": "%K"}},"duration": "%T","size": "%b","status": "%s","resp_headers":{"Content-Type":["%M;%^"]}}

# Treaefik CLF flavor
#log-format %h - %e [%d:%t %^] "%r" %s %b "%R" "%u" %^ "%v" "%U" %Lms

# In addition to specifying the raw log/date/time formats, for
# simplicity, any of the following predefined log format names can be
# supplied to the log/date/time-format variables. GoAccess can also
Expand All @@ -132,6 +135,7 @@
#log-format AWSELB
#log-format AWSS3
#log-format CADDY
#log-format TRAEFIKCLF

######################################
# UI Options
Expand Down
1 change: 1 addition & 0 deletions goaccess.1
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ one variable and another predefined name in another variable.
AWSS3 - Amazon Simple Storage Service (S3)
AWSALB - Amazon Application Load Balancer
CADDY - Caddy's JSON Structured format
TRAEFIKCLF - Traefik's CLF flavor
.IP
.I Note:
Piping data into GoAccess won't prompt a log/date/time configuration dialog,
Expand Down
12 changes: 11 additions & 1 deletion src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ static GEnum LOGTYPE[] = {
{"AWSS3" , AWSS3} ,
{"CADDY" , CADDY} ,
{"AWSALB" , AWSALB} ,
{"TRAEFIKCLF" , TRAEFIKCLF} ,
};

static const GPreConfLog logs = {
Expand All @@ -84,7 +85,9 @@ static const GPreConfLog logs = {
"\"%k\", \"proto\": \"%K\" } }, \"duration\": \"%T\", \"size\": \"%b\","
"\"status\": \"%s\", \"resp_headers\": { \"Content-Type\": [\"%M\"] } }",

"%^ %dT%t.%^ %v %h:%^ %^ %^ %T %^ %s %^ %^ %b \"%r\" \"%u\" %k %K %^" /* Amazon ALB */
"%^ %dT%t.%^ %v %h:%^ %^ %^ %T %^ %s %^ %^ %b \"%r\" \"%u\" %k %K %^", /* Amazon ALB */

"%h - %e [%d:%t %^] \"%r\" %s %b \"%R\" \"%u\" %^ \"%v\" \"%U\" %Lms" /* Traefik's CLF flavor with header */
};

static const GPreConfTime times = {
Expand Down Expand Up @@ -399,6 +402,8 @@ get_selected_format_idx (void) {
return CADDY;
else if (strcmp (conf.log_format, logs.awsalb) == 0)
return AWSALB;
else if (strcmp (conf.log_format, logs.traefikclf) == 0)
return TRAEFIKCLF;
else
return (size_t) -1;
}
Expand Down Expand Up @@ -448,6 +453,9 @@ get_selected_format_str (size_t idx) {
case AWSALB:
fmt = alloc_string (logs.awsalb);
break;
case TRAEFIKCLF:
fmt = alloc_string (logs.traefikclf);
break;
}

return fmt;
Expand All @@ -467,6 +475,7 @@ get_selected_date_str (size_t idx) {
case COMBINED:
case VCOMBINED:
case AWSS3:
case TRAEFIKCLF:
fmt = alloc_string (dates.apache);
break;
case AWSELB:
Expand Down Expand Up @@ -505,6 +514,7 @@ get_selected_time_str (size_t idx) {
case VCOMMON:
case W3C:
case AWSS3:
case TRAEFIKCLF:
fmt = alloc_string (times.fmt24);
break;
case CLOUDSTORAGE:
Expand Down
2 changes: 2 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ typedef enum LOGTYPE {
AWSS3,
CADDY,
AWSALB,
TRAEFIKCLF,
} GLogType;

/* predefined log times */
Expand Down Expand Up @@ -89,6 +90,7 @@ typedef struct GPreConfLog_ {
const char *awss3;
const char *caddy;
const char *awsalb;
const char *traefikclf;
} GPreConfLog;

/* *INDENT-OFF* */
Expand Down
1 change: 1 addition & 0 deletions src/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,7 @@ render_confdlg (Logs *logs, GSpinner *spinner) {
"AWS Simple Storage Service (S3)",
"CADDY JSON Structured",
"AWS Application Load Balancer",
"Traefik CLF flavor"
};
n = ARRAY_SIZE (choices);
getmaxyx (stdscr, y, x);
Expand Down

0 comments on commit 01c074a

Please sign in to comment.