Skip to content

Commit

Permalink
add fluent socket option
Browse files Browse the repository at this point in the history
  • Loading branch information
koid committed Jun 22, 2018
1 parent de27cad commit b63f8c9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
3 changes: 3 additions & 0 deletions fluentd.example.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<source>
@type unix
</source>
<source>
@type forward
</source>
Expand Down
29 changes: 21 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ var (
checkpointTablePrefix string
tagKey string

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

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

tagKey = os.Getenv("TAG_KEY")


fluentSocket = os.Getenv("FLUENT_SOCKET")
if len(os.Getenv("FLUENT_HOST")) != 0 {
fluentHost = os.Getenv("FLUENT_HOST")
}
Expand All @@ -67,11 +69,22 @@ func init() {
}

func initFluentLogger(retry int) *fluent.Fluent {
_l, err := fluent.New(fluent.Config{
MarshalAsJSON: true,
FluentHost: fluentHost,
FluentPort: fluentPort,
})
var cfg fluent.Config
if len(fluentSocket) > 0 {
cfg = fluent.Config{
MarshalAsJSON: true,
FluentNetwork: "unix",
FluentSocketPath: fluentSocket,
}
} else {
cfg = fluent.Config{
MarshalAsJSON: true,
FluentHost: fluentHost,
FluentPort: fluentPort,
}
}

_l, err := fluent.New(cfg)
if err != nil {
if retry == 0 {
log.Fatalf("fluent.New returned error: %v", err)
Expand Down

0 comments on commit b63f8c9

Please sign in to comment.