Skip to content

Commit

Permalink
Use go.artefactual.dev/tools/log
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed Jun 26, 2023
1 parent 5cff5a3 commit e68c928
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/fsnotify/fsnotify v1.6.0
github.com/go-logr/logr v1.2.4
github.com/go-logr/zapr v1.2.4
github.com/go-sql-driver/mysql v1.7.1
github.com/golang-migrate/migrate/v4 v4.16.2
github.com/golang/mock v1.6.0
Expand All @@ -30,6 +29,7 @@ require (
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
github.com/uber-go/tally v3.4.3+incompatible
go.artefactual.dev/tools v0.0.0-20230626164816-003cda7e2583
go.uber.org/cadence v0.19.1
go.uber.org/yarpc v1.70.2
go.uber.org/zap v1.24.0
Expand Down Expand Up @@ -75,6 +75,7 @@ require (
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,10 @@ github.com/yvasiyarov/newrelic_platform_go v0.0.0-20140908184405-b21fdbd4370f/go
github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea h1:CyhwejzVGvZ3Q2PSbQ4NRRYn+ZWv5eS1vlaEusT+bAI=
github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea/go.mod h1:eNr558nEUjP8acGw8FFjTeWvSgU1stO7FAO6eknhHe4=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
go.artefactual.dev/tools v0.0.0-20230626163213-a7a903e5ddb4 h1:F+s1pbI/got7XXdl/Pu5kz7KmC3IsjzG55fRWJzoPho=
go.artefactual.dev/tools v0.0.0-20230626163213-a7a903e5ddb4/go.mod h1:VM9uoKuK6IcDIitYuWvqyaxxLajGxJHDbqnwNfgaCpU=
go.artefactual.dev/tools v0.0.0-20230626164816-003cda7e2583 h1:03F0o9d3qYfNjyfRzTEZEyWJRUe9uN6uN/ot6s3sAyY=
go.artefactual.dev/tools v0.0.0-20230626164816-003cda7e2583/go.mod h1:VM9uoKuK6IcDIitYuWvqyaxxLajGxJHDbqnwNfgaCpU=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
Expand Down
27 changes: 9 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ import (
"time"

"github.com/go-logr/logr"
"github.com/go-logr/zapr"
"github.com/oklog/run"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"go.artefactual.dev/tools/log"
cadencesdk_activity "go.uber.org/cadence/activity"
cadencesdk_client "go.uber.org/cadence/client"
cadencesdk_workflow "go.uber.org/cadence/workflow"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

"github.com/artefactual-labs/enduro/internal/api"
"github.com/artefactual-labs/enduro/internal/batch"
Expand Down Expand Up @@ -79,28 +78,20 @@ func main() {
var logger logr.Logger
var zlogger *zap.Logger
{
var zconfig zap.Config
if config.Debug {
encoderConfig := zap.NewDevelopmentEncoderConfig()
encoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
zconfig = zap.NewDevelopmentConfig()
zconfig.EncoderConfig = encoderConfig
} else {
zconfig = zap.NewProductionConfig()
}
logger = log.New(os.Stderr, log.WithName(appName), log.WithDebug(config.Debug))

zlogger, err = zconfig.Build(zap.AddCallerSkip(1))
zlogger = zlogger.Named(appName)
defer func() { _ = zlogger.Sync() }()
if err != nil {
fmt.Printf("Failed to set up logger %v", err)
var ok bool
zlogger, ok = log.Underlying(logger)
if !ok {
fmt.Println("Failed to configure logger.")
os.Exit(1)
}

logger = zapr.NewLogger(zlogger)
logger.Info("Starting...", "version", version, "pid", os.Getpid())
defer log.Sync(logger)
}

logger.Info("Starting...", "version", version, "pid", os.Getpid())

if configFileFound {
logger.Info("Configuration file loaded.", "path", v.ConfigFileUsed())
} else {
Expand Down

0 comments on commit e68c928

Please sign in to comment.