Skip to content

Commit

Permalink
Merge pull request #2 from koid/feature/default-tag-option
Browse files Browse the repository at this point in the history
add TagPrefix option
  • Loading branch information
koid authored Jul 23, 2018
2 parents f99d7a5 + 2feb27b commit 714fd22
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ var (
checkpointTablePrefix string
tagKey string

fluentSocket string
fluentHost = "localhost"
fluentPort = 24224
fluentTagPrefix string
fluentSocket string
fluentHost = "localhost"
fluentPort = 24224

dogStatsdAddr string
dogStatsdTags []string
Expand All @@ -47,7 +48,8 @@ func init() {
}

tagKey = os.Getenv("TAG_KEY")


fluentTagPrefix = os.Getenv("FLUENT_TAG_PREFIX")
fluentSocket = os.Getenv("FLUENT_SOCKET")
if len(os.Getenv("FLUENT_HOST")) != 0 {
fluentHost = os.Getenv("FLUENT_HOST")
Expand All @@ -73,12 +75,14 @@ func initFluentLogger(retry int) *fluent.Fluent {
if len(fluentSocket) > 0 {
cfg = fluent.Config{
MarshalAsJSON: true,
TagPrefix: fluentTagPrefix,
FluentNetwork: "unix",
FluentSocketPath: fluentSocket,
}
} else {
cfg = fluent.Config{
MarshalAsJSON: true,
TagPrefix: fluentTagPrefix,
FluentHost: fluentHost,
FluentPort: fluentPort,
}
Expand Down Expand Up @@ -196,7 +200,12 @@ func main() {
}
var tag string
if tagKey != "" {
tag, _ = message[tagKey].(string)
// append to tag
if val, ok := message[tagKey].(string); ok {
tag = val
} else {
tag = "unknown"
}
} else {
tag = "default"
}
Expand Down

0 comments on commit 714fd22

Please sign in to comment.