Восстановлен логгинг метрик в statsd, если таковой указан в конфигурации

This commit is contained in:
ErickSkrauch 2017-08-16 15:23:03 +03:00
parent 06b8e88346
commit 4bf146dd43
4 changed files with 46 additions and 7 deletions

View File

@ -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

10
Gopkg.lock generated
View File

@ -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

30
bootstrap/bootstrap.go Normal file
View File

@ -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
}

View File

@ -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()}