Browse files

Append designated tag if `tag` option is set with `append_to_tag` opt…

…ion.
  • Loading branch information...
1 parent 5749938 commit d2d5340aaec550134f30633662dcfed6f9ff1f8a @kentaro committed Jul 2, 2012
Showing with 53 additions and 1 deletion.
  1. +30 −0 README.md
  2. +5 −1 lib/fluent/plugin/out_rewrite.rb
  3. +18 −0 test/plugin/test_out_rewrite.rb
View
30 README.md
@@ -37,6 +37,12 @@ matching and re-emit them.
append_to_tag true
fallback others
</rule>
+ <rule>
+ key is_loggged_in
+ pattern 1
+ append_to_tag true
+ tag user
+ </rule>
</match>
```
@@ -145,6 +151,30 @@ This time, the messabe above will be re-emmited as the message below:
apache.log.others { "path" : "/foo/bar" }
```
+If `tag` option set,
+
+```
+<rule>
+ key is_loggged_in
+ pattern 1
+ append_to_tag true
+ tag user
+</rule>
+```
+
+the value designated by `tag` will be appended to the original tag, that is:
+
+
+```
+test { "is_logged_in" => "1" }
+```
+
+will be
+
+```
+test.user { "is_logged_in" => "1" }
+```
+
### rule: last
If you set `last` option to true, rewriting chain stops applying rule where the pattern matches first.
View
6 lib/fluent/plugin/out_rewrite.rb
@@ -93,7 +93,11 @@ def apply_rule(rule, tag, record)
end
if rule["append_to_tag"]
- matched.captures.each { |m| tag << ".#{m}" }
+ if rule["tag"]
+ tag << ".#{rule["tag"]}"
+ else
+ matched.captures.each { |m| tag << ".#{m}" }
+ end
end
if rule["last"]
View
18 test/plugin/test_out_rewrite.rb
@@ -140,6 +140,24 @@ def test_rewrite_append_tag
[ "test.others", { "path" => "/unmatched/path" } ],
d2.instance.rewrite("test", { "path" => "/unmatched/path" })
)
+
+ d3 = create_driver(%[
+ <rule>
+ key is_logged_in
+ pattern 1
+ append_to_tag true
+ tag user
+ </rule>
+ ])
+
+ assert_equal(
+ [ "test.user", { "is_logged_in" => "1" } ],
+ d3.instance.rewrite("test", { "is_logged_in" => "1" })
+ )
+ assert_equal(
+ [ "test", { "is_logged_in" => "0" } ],
+ d3.instance.rewrite("test", { "is_logged_in" => "0" })
+ )
end
def test_last

0 comments on commit d2d5340

Please sign in to comment.