Skip to content

Commit b7231d9

Browse files
Watson1978claude
andcommitted
Add parser/apache.md
lib/fluent/plugin/parser_apache.rb registers the "apache" parser via `Plugin.register_parser("apache", self)`, but it had no documentation page while apache2 and apache_error do. The plugin is a RegexpParser subclass with only two defaults: config_set_default :expression, /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$/ config_set_default :time_format, "%d/%b/%Y:%H:%M:%S %z" The page follows parser/nginx.md, which documents the other RegexpParser subclass. The Example output was verified by running the parser against the sample line: all fields are returned as String and "-" is kept verbatim, unlike apache2 which casts code/size to Integer and maps "-" to nil. The new page is linked from the three places that list the built-in parsers: SUMMARY.md, parser/README.md and configuration/parse-section.md. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
1 parent f3b17ad commit b7231d9

4 files changed

Lines changed: 57 additions & 0 deletions

File tree

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
* [stdout](filter/stdout.md)
118118
* [Parser Plugins](parser/README.md)
119119
* [regexp](parser/regexp.md)
120+
* [apache](parser/apache.md)
120121
* [apache2](parser/apache2.md)
121122
* [apache\_error](parser/apache_error.md)
122123
* [nginx](parser/nginx.md)

configuration/parse-section.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ The `@type` parameter specifies the type of the parser plugin.
4646
Here's the list of built-in parser plugins:
4747

4848
* [`regexp`](../parser/regexp.md)
49+
* [`apache`](../parser/apache.md)
4950
* [`apache2`](../parser/apache2.md)
5051
* [`apache_error`](../parser/apache_error.md)
5152
* [`nginx`](../parser/nginx.md)

parser/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ this case, several options are available to allow read access:
5353
## List of Built-in Parsers
5454

5555
* [`regexp`](regexp.md)
56+
* [`apache`](apache.md)
5657
* [`apache2`](apache2.md)
5758
* [`apache_error`](apache_error.md)
5859
* [`nginx`](nginx.md)

parser/apache.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# apache
2+
3+
The `apache` parser plugin parses the default Apache logs \(Common Log Format with the optional referer and user-agent fields\).
4+
5+
## Parameters
6+
7+
See [Parse Section Configurations](../configuration/parse-section.md).
8+
9+
## Regexp Patterns
10+
11+
Here is the regexp and time format patterns of this plugin:
12+
13+
```text
14+
expression /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$/
15+
time_format %d/%b/%Y:%H:%M:%S %z
16+
```
17+
18+
`host`, `user`, `method`, `path`, `code`, `size`, `referer` and `agent` are included in the event record. `time` is used for the event time.
19+
20+
This plugin is a [`regexp`](regexp.md) parser with the above defaults, so every field is kept as a string and a `-` value is kept as it is.
21+
22+
## Difference from `apache2`
23+
24+
The [`apache2`](apache2.md) parser accepts a wider range of lines: its `path` may contain spaces, the protocol token after the path is optional, and `path`, `referer` and `agent` may contain escaped double quotes. It also converts `code` and `size` into the integer type and interprets the `-` value as `nil`. The `apache` parser does none of these: it requires the protocol token, does not allow a space in `path`, and returns all the fields as a string.
25+
26+
## Example
27+
28+
This incoming event:
29+
30+
```text
31+
192.168.0.1 - - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777 "-" "Opera/12.0"
32+
```
33+
34+
is parsed as:
35+
36+
```text
37+
time:
38+
1362020400 (28/Feb/2013:12:00:00 +0900)
39+
40+
record:
41+
{
42+
"host" : "192.168.0.1",
43+
"user" : "-",
44+
"method" : "GET",
45+
"path" : "/",
46+
"code" : "200",
47+
"size" : "777",
48+
"referer": "-",
49+
"agent" : "Opera/12.0"
50+
}
51+
```
52+
53+
If this article is incorrect or outdated, or omits critical information, please [let us know](https://github.com/fluent/fluentd-docs-gitbook/issues?state=open). [Fluentd](http://www.fluentd.org/) is an open-source project under [Cloud Native Computing Foundation \(CNCF\)](https://cncf.io/). All components are available under the Apache 2 License.
54+

0 commit comments

Comments
 (0)