Skip to content

Commit

Permalink
updated documentation and replaced function with strings.Replace call
Browse files Browse the repository at this point in the history
  • Loading branch information
jxstanford committed Jun 11, 2016
1 parent a6d2fa4 commit 8b86123
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
4 changes: 4 additions & 0 deletions docs/source/config/encoders/esjson.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Config:
the JSON output. Defaults to including all of the messages dynamic
fields. If ``dynamic_fields`` is non-empty, then the ``fields`` list *must*
contain "DynamicFields" or an error will be raised.
- replace_dots_with (string):
This specifies a string to use as a replacement in JSON output field names.

Example

Expand All @@ -73,6 +75,8 @@ Example
index = "%{Type}-%{%Y.%m.%d}"
es_index_from_timestamp = true
type_name = "%{Type}"
replace_dots_with = "_"
[ESJsonEncoder.field_mappings]
Timestamp = "@timestamp"
Severity = "level"
Expand Down
3 changes: 3 additions & 0 deletions docs/source/config/encoders/eslogstashv0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Config:
the JSON output. Defaults to including all of the messages dynamic
fields. If ``dynamic_fields`` is non-empty, then the ``fields`` list *must*
contain "DynamicFields" or an error will be raised.
- replace_dots_with (string):
This specifies a string to use as a replacement in JSON output field names.

Example

Expand All @@ -78,6 +80,7 @@ Example
[ESLogstashV0Encoder]
es_index_from_timestamp = true
type_name = "%{Type}"
replace_dots_with = "_"
[ElasticSearchOutput]
message_matcher = "Type == 'nginx.access'"
Expand Down
16 changes: 1 addition & 15 deletions plugins/elasticsearch/encoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,6 @@ func writeUTF16Escape(b *bytes.Buffer, c rune) {
b.WriteByte(lowerhex[c&0xF])
}

// replaceDots substitutes a string for all instances of '.' characters
// in another string.
func replaceDots(str string, sub string) (cname string) {
buf := bytes.Buffer{}
for _, r := range str {
if r == '.' {
buf.WriteString(sub)
} else {
buf.WriteRune(r)
}
}
return buf.String()
}

// Go json encoder will blow up on invalid utf8 so we use this custom json
// encoder. Also, go json encoder generates these funny \U escapes which I
// don't think are valid json.
Expand Down Expand Up @@ -109,7 +95,7 @@ func writeField(first bool, b *bytes.Buffer, f *message.Field, raw bool, replace
}

if replaceDotsWith != "." {
writeQuotedString(b, replaceDots(f.GetName(), replaceDotsWith))
writeQuotedString(b, strings.Replace(f.GetName(), ".", replaceDotsWith, -1))
} else {
writeQuotedString(b, f.GetName())
}
Expand Down

0 comments on commit 8b86123

Please sign in to comment.