Skip to content

Commit

Permalink
observability: format logs as json (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn authored Oct 1, 2024
1 parent 93fe620 commit c24cabd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
10 changes: 5 additions & 5 deletions app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ func main() {
panic(err)
}

// If fails, it means that the node is not reachable
if _, err := chainClient.GetLatestHeight(ctx); err != nil {
panic(err)
}

encCfg := app.MakeEncodingConfig()

// logger
Expand All @@ -122,6 +117,11 @@ func main() {
}
logger.Info("Starting sidecar query server")

// If fails, it means that the node is not reachable
if _, err := chainClient.GetLatestHeight(ctx); err != nil {
panic(err)
}

sidecarQueryServer, err := NewSideCarQueryServer(encCfg.Marshaler, *config, logger)
if err != nil {
panic(err)
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/osmosis-labs/sqs

go 1.22.4

toolchain go1.22.5

require (
cosmossdk.io/math v1.3.0
cosmossdk.io/store v1.1.0
Expand All @@ -15,7 +13,7 @@ require (
github.com/osmosis-labs/osmosis/osmomath v0.0.13
github.com/osmosis-labs/osmosis/osmoutils v0.0.13
github.com/osmosis-labs/osmosis/v26 v26.0.0-rc1
github.com/osmosis-labs/sqs/sqsdomain v0.26.0
github.com/osmosis-labs/sqs/sqsdomain v0.26.1-0.20240927203000-382296c78ee2
github.com/prometheus/client_golang v1.20.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/viper v1.19.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,8 @@ github.com/osmosis-labs/osmosis/x/epochs v0.0.5-0.20240825083448-87db4447a1ff h1
github.com/osmosis-labs/osmosis/x/epochs v0.0.5-0.20240825083448-87db4447a1ff/go.mod h1:7ylCTvH4gEtZ5E8paiwSjmOzOKOOls8Br45W9uwWnP0=
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20240825083448-87db4447a1ff h1:OZGMwv/Km6xnIB16d4zghFf0x7K9JlWqRaxgOVBIv7Y=
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.0-20240825083448-87db4447a1ff/go.mod h1:AXHoG4L1AMDCMEGeSdzcy7ik2mBt5fTyzEAWlGt+aSc=
github.com/osmosis-labs/sqs/sqsdomain v0.26.0 h1:Yji7lFT7bnYM6Xe/TI30SXvnQjjk8wBWY0QeOWJIo3Y=
github.com/osmosis-labs/sqs/sqsdomain v0.26.0/go.mod h1:HPczKMkVKve0kbuTvngNSZ3TAonApOhYdWSQ4WbAalY=
github.com/osmosis-labs/sqs/sqsdomain v0.26.1-0.20240927203000-382296c78ee2 h1:bZR8CTulFkHKeOAhZhipipNF76GSHgauodoB9UFaULc=
github.com/osmosis-labs/sqs/sqsdomain v0.26.1-0.20240927203000-382296c78ee2/go.mod h1:bWEvSwh1yioFdxxHrU1TYAUCM4Go3Z3DkWY+GTWL2b4=
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
Expand Down
12 changes: 9 additions & 3 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,15 @@ func (l *loggerImpl) Warn(msg string, fields ...zapcore.Field) {
// If fileName is non-empty, it pipes logs to file and stdout.
// if filename is empty, it pipes logs only to stdout.
func NewLogger(isProduction bool, fileName string, logLevelStr string) (Logger, error) {
loggerConfig := zap.NewProductionConfig()
if !isProduction {
loggerConfig = zap.NewDevelopmentConfig()
loggerConfig := zap.NewDevelopmentConfig()
if isProduction {
loggerConfig = zap.NewProductionConfig()

// Ensure JSON output
loggerConfig.Encoding = "json"

// Configure timestamp format
loggerConfig.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
}

logLevel := zap.InfoLevel
Expand Down

0 comments on commit c24cabd

Please sign in to comment.