From c24cabdc268f834d92b0987ee4488301dbe8922a Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 1 Oct 2024 14:16:44 -0700 Subject: [PATCH] observability: format logs as json (#523) --- app/main.go | 10 +++++----- go.mod | 4 +--- go.sum | 4 ++-- log/logger.go | 12 +++++++++--- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/main.go b/app/main.go index fad9df4b..d6becb59 100644 --- a/app/main.go +++ b/app/main.go @@ -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 @@ -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) diff --git a/go.mod b/go.mod index a9863401..ac271ed9 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 47a230d8..973b9bae 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/log/logger.go b/log/logger.go index c80c3463..08745863 100644 --- a/log/logger.go +++ b/log/logger.go @@ -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