Skip to content

Commit

Permalink
Merge pull request #60 from checkr/zz/es-logging-format
Browse files Browse the repository at this point in the history
Change back to string format and only stdout with evalResult
  • Loading branch information
zhouzhuojie authored Oct 28, 2017
2 parents 5d7d264 + b56ff28 commit 52acc88
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .fsw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ triggers:
- './pkg'
- './swagger_gen'
- '!**/*_test.go'
cmd: make build && make run | jq .
cmd: make build && make run
shell: true
delay: 1000ms
stop_timeout: 500ms
Expand Down
31 changes: 12 additions & 19 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,18 @@ import (

// Config is the whole configuration of the app
var Config = struct {
Host string `env:"HOST" envDefault:"127.0.0.1"`
PProfEnabled bool `env:"FLAGR_PPROF_ENABLED" envDefault:"true"`

DBDriver string `env:"FLAGR_DB_DBDRIVER" envDefault:"mysql"`
DBConnectionStr string `env:"FLAGR_DB_DBCONNECTIONSTR" envDefault:"root:@tcp(127.0.0.1:18100)/flagr?parseTime=true"`

CORSEnabled bool `env:"FLAGR_CORS_ENABLED" envDefault:"true"`

SentryEnabled bool `env:"FLAGR_SENTRY_ENABLED" envDefault:"false"`
SentryDSN string `env:"FLAGR_SENTRY_DSN" envDefault:""`

NewRelicEnabled bool `env:"FLAGR_NEWRELIC_ENABLED" envDefault:"false"`
NewRelicAppName string `env:"FLAGR_NEWRELIC_NAME" envDefault:"flagr"`
NewRelicKey string `env:"FLAGR_NEWRELIC_KEY" envDefault:""`

EvalCacheRefreshTimeout time.Duration `env:"FLAGR_EVALCACHE_REFRESHTIMEOUT" envDefault:"59s"`
EvalCacheRefreshInterval time.Duration `env:"FLAGR_EVALCACHE_REFRESHINTERVAL" envDefault:"3s"`

Host string `env:"HOST" envDefault:"127.0.0.1"`
PProfEnabled bool `env:"FLAGR_PPROF_ENABLED" envDefault:"true"`
DBDriver string `env:"FLAGR_DB_DBDRIVER" envDefault:"mysql"`
DBConnectionStr string `env:"FLAGR_DB_DBCONNECTIONSTR" envDefault:"root:@tcp(127.0.0.1:18100)/flagr?parseTime=true"`
CORSEnabled bool `env:"FLAGR_CORS_ENABLED" envDefault:"true"`
SentryEnabled bool `env:"FLAGR_SENTRY_ENABLED" envDefault:"false"`
SentryDSN string `env:"FLAGR_SENTRY_DSN" envDefault:""`
NewRelicEnabled bool `env:"FLAGR_NEWRELIC_ENABLED" envDefault:"false"`
NewRelicAppName string `env:"FLAGR_NEWRELIC_NAME" envDefault:"flagr"`
NewRelicKey string `env:"FLAGR_NEWRELIC_KEY" envDefault:""`
EvalCacheRefreshTimeout time.Duration `env:"FLAGR_EVALCACHE_REFRESHTIMEOUT" envDefault:"59s"`
EvalCacheRefreshInterval time.Duration `env:"FLAGR_EVALCACHE_REFRESHINTERVAL" envDefault:"3s"`
RecorderEnabled bool `env:"FLAGR_RECORDER_ENABLED" envDefault:"false"`
RecorderType string `env:"FLAGR_RECORDER_TYPE" envDefault:"kafka"`
RecorderKafkaBrokers string `env:"FLAGR_RECORDER_KAFKA_BROKERS" envDefault:":9092"`
Expand All @@ -55,7 +49,6 @@ func init() {
}

func setupLogrus() {
logrus.SetFormatter(&logrus.JSONFormatter{})
logrus.SetOutput(os.Stdout)
logrus.SetLevel(logrus.InfoLevel)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/handler/eval.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package handler

import (
"encoding/json"
"fmt"

"github.com/checkr/flagr/pkg/config"
"github.com/checkr/flagr/pkg/entity"
"github.com/checkr/flagr/pkg/util"
"github.com/checkr/flagr/swagger_gen/models"
"github.com/checkr/flagr/swagger_gen/restapi/operations/evaluation"
"github.com/sirupsen/logrus"

"github.com/davecgh/go-spew/spew"
"github.com/go-openapi/runtime/middleware"
Expand Down Expand Up @@ -131,7 +131,8 @@ func evalFlag(evalContext models.EvalContext) *models.EvalResult {
}

var logEvalResult = func(r *models.EvalResult, dataRecordsEnabled bool) {
logrus.WithField("flagr_evalresult", r).Info()
jsonStr, _ := json.Marshal(struct{ FlagEvalResult *models.EvalResult }{FlagEvalResult: r})
fmt.Println(string(jsonStr))

if !config.Config.RecorderEnabled || !dataRecordsEnabled {
return
Expand Down

0 comments on commit 52acc88

Please sign in to comment.