From b63f8c9c6cb41acd41fe9be45388268fc5ffe769 Mon Sep 17 00:00:00 2001 From: koid Date: Fri, 22 Jun 2018 12:17:58 +0900 Subject: [PATCH] add fluent socket option --- fluentd.example.conf | 3 +++ main.go | 29 +++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/fluentd.example.conf b/fluentd.example.conf index 2f85829..4c2b4ae 100644 --- a/fluentd.example.conf +++ b/fluentd.example.conf @@ -1,3 +1,6 @@ + + @type unix + @type forward diff --git a/main.go b/main.go index 1cb2662..ea138d7 100644 --- a/main.go +++ b/main.go @@ -26,8 +26,9 @@ var ( checkpointTablePrefix string tagKey string - fluentHost = "localhost" - fluentPort = 24224 + fluentSocket string + fluentHost = "localhost" + fluentPort = 24224 dogStatsdAddr string dogStatsdTags []string @@ -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") } @@ -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)