Skip to content

Instantly share code, notes, and snippets.

@acouvreur
Last active April 15, 2024 17:51
Show Gist options
  • Save acouvreur/e1be47013c182fc85f03351210ae13d7 to your computer and use it in GitHub Desktop.
Save acouvreur/e1be47013c182fc85f03351210ae13d7 to your computer and use it in GitHub Desktop.
Traefik accessLog regex with groups - CLF (Common Log Format) parsing for log collection
## Regex flavors: PCRE
^(?<client>\S+) \S+ (?<userid>\S+) \[(?<datetime>[^\]]+)\] "(?<method>[A-Z]+) (?<request>[^ "]+)? HTTP\/[0-9.]+" (?<status>[0-9]{3}) (?<size>[0-9]+|-) "(?<referrer>\S+)" "(?<user_agent>\S+)" (?<requestsTotal>)\d+ "(?<router>\S+)" "(?<server_URL>\S+)" (?<request_duration>\d+)ms
## Regex flavors: .NET, Java 7, XRegExp, PCRE 7, Perl 5.10, Ruby 1.9
^(?P<client>\S+) \S+ (?P<userid>\S+) \[(?P<datetime>[^\]]+)\] "(?P<method>[A-Z]+) (?P<request>[^ "]+)? HTTP\/[0-9.]+" (?P<status>[0-9]{3}) (?P<size>[0-9]+|-) "(?P<referrer>\S+)" "(?P<user_agent>\S+)" (?P<requestsTotal>)\d+ "(?P<router>\S+)" "(?P<server_URL>\S+)" (?P<request_duration>\d+)ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment