From 4bf146dd437ba563d46bbdcaabd974fee1c57855 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 16 Aug 2017 15:23:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BE=D1=81=D1=81=D1=82=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=BB=D0=BE=D0=B3=D0=B3=D0=B8?= =?UTF-8?q?=D0=BD=D0=B3=20=D0=BC=D0=B5=D1=82=D1=80=D0=B8=D0=BA=20=D0=B2=20?= =?UTF-8?q?statsd,=20=D0=B5=D1=81=D0=BB=D0=B8=20=D1=82=D0=B0=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BE=D0=B9=20=D1=83=D0=BA=D0=B0=D0=B7=D0=B0=D0=BD=20?= =?UTF-8?q?=D0=B2=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 1 + Gopkg.lock | 10 ++++++++-- bootstrap/bootstrap.go | 30 ++++++++++++++++++++++++++++++ cmd/serve.go | 12 +++++++----- 4 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 bootstrap/bootstrap.go diff --git a/Dockerfile b/Dockerfile index aa8d887..7cce980 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,7 @@ WORKDIR /go/src/app COPY ./Gopkg.* /go/src/app/ COPY ./main.go /go/src/app/ +COPY ./bootstrap /go/src/app/bootstrap COPY ./cmd /go/src/app/cmd COPY ./daemon /go/src/app/daemon COPY ./db /go/src/app/db diff --git a/Gopkg.lock b/Gopkg.lock index ad9b00b..5d3cd6f 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -50,9 +50,15 @@ [[projects]] branch = "master" name = "github.com/mono83/slf" - packages = [".","params","rays","recievers/ansi","wd"] + packages = [".","params","rays","recievers","recievers/ansi","recievers/statsd","wd"] revision = "8188a95c8d6b74c43953abb38b8bd6fdbc412ff5" +[[projects]] + branch = "master" + name = "github.com/mono83/udpwriter" + packages = ["."] + revision = "a064bd7e3acfda563ea680b913b9ef24b7a73e15" + [[projects]] branch = "master" name = "github.com/pelletier/go-toml" @@ -111,6 +117,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "d297b8c1b79f47828a7fab2a451a02e8be62bd0e92f2c4162feffc611893bfd8" + inputs-digest = "ec0031edfe5ff25a05e871c72a7ae46c52cefad9f1a9fe5bb54c1b293f965c89" solver-name = "gps-cdcl" solver-version = 1 diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go new file mode 100644 index 0000000..9c70eef --- /dev/null +++ b/bootstrap/bootstrap.go @@ -0,0 +1,30 @@ +package bootstrap + +import ( + "os" + + "github.com/mono83/slf/rays" + "github.com/mono83/slf/recievers/ansi" + "github.com/mono83/slf/recievers/statsd" + "github.com/mono83/slf/wd" +) + +func CreateLogger(statsdAddr string) (wd.Watchdog, error) { + wd.AddReceiver(ansi.New(true, true, false)) + if statsdAddr != "" { + hostname, _ := os.Hostname() + statsdReceiver, err := statsd.NewReceiver(statsd.Config{ + Address: statsdAddr, + Prefix: "ely.skinsystem." + hostname + ".app.", + FlushEvery: 1, + }) + + if err != nil { + return nil, err + } + + wd.AddReceiver(statsdReceiver) + } + + return wd.New("", "").WithParams(rays.Host), nil +} diff --git a/cmd/serve.go b/cmd/serve.go index faa8b9d..77f1bed 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -2,13 +2,12 @@ package cmd import ( "fmt" + "log" - "github.com/mono83/slf/rays" - "github.com/mono83/slf/recievers/ansi" - "github.com/mono83/slf/wd" "github.com/spf13/cobra" "github.com/spf13/viper" + "elyby/minecraft-skinsystem/bootstrap" "elyby/minecraft-skinsystem/daemon" "elyby/minecraft-skinsystem/db" "elyby/minecraft-skinsystem/ui" @@ -18,8 +17,11 @@ var serveCmd = &cobra.Command{ Use: "serve", Short: "Runs the system server skins", Run: func(cmd *cobra.Command, args []string) { - wd.AddReceiver(ansi.New(true, true, false)) - logger := wd.New("", "").WithParams(rays.Host) + logger, err := bootstrap.CreateLogger(viper.GetString("statsd.addr")) + if err != nil { + log.Fatal(fmt.Printf("Cannot initialize logger: %v", err)) + } + logger.Info("Logger successfully initialized") storageFactory := db.StorageFactory{Config: viper.GetViper()}