From bcce1023881944581006d34fd507122f3bc2b99c Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Mon, 23 May 2022 14:29:15 -0400 Subject: [PATCH] more logging things --- internal/cmd/api.go | 2 +- internal/cmd/scheduler.go | 2 +- internal/cmd/worker.go | 3 ++- internal/cmdutil/cmdutil.go | 11 ++++++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/internal/cmd/api.go b/internal/cmd/api.go index 8e142d5..8386951 100644 --- a/internal/cmd/api.go +++ b/internal/cmd/api.go @@ -24,7 +24,7 @@ func APICmd(ctx context.Context) *cobra.Command { port, _ = strconv.Atoi(os.Getenv("PORT")) } - logger := cmdutil.NewLogger(false) + logger := cmdutil.NewLogger("api") defer func() { _ = logger.Sync() }() statsd, err := cmdutil.NewStatsdClient() diff --git a/internal/cmd/scheduler.go b/internal/cmd/scheduler.go index ce25e25..8729857 100644 --- a/internal/cmd/scheduler.go +++ b/internal/cmd/scheduler.go @@ -29,7 +29,7 @@ func SchedulerCmd(ctx context.Context) *cobra.Command { Args: cobra.ExactArgs(0), Short: "Schedules jobs and runs several maintenance tasks periodically.", RunE: func(cmd *cobra.Command, args []string) error { - logger := cmdutil.NewLogger(false) + logger := cmdutil.NewLogger("scheduler") defer func() { _ = logger.Sync() }() statsd, err := cmdutil.NewStatsdClient() diff --git a/internal/cmd/worker.go b/internal/cmd/worker.go index 915cb07..943687f 100644 --- a/internal/cmd/worker.go +++ b/internal/cmd/worker.go @@ -34,7 +34,8 @@ func WorkerCmd(ctx context.Context) *cobra.Command { return fmt.Errorf("need a queue to work on") } - logger := cmdutil.NewLogger(false) + svc := fmt.Sprintf("worker: %s", queueID) + logger := cmdutil.NewLogger(svc) defer func() { _ = logger.Sync() }() tag := fmt.Sprintf("worker:%s", queueID) diff --git a/internal/cmdutil/cmdutil.go b/internal/cmdutil/cmdutil.go index 110a60e..7aea93b 100644 --- a/internal/cmdutil/cmdutil.go +++ b/internal/cmdutil/cmdutil.go @@ -12,9 +12,14 @@ import ( "go.uber.org/zap" ) -func NewLogger(debug bool) *zap.Logger { - logger, _ := zap.NewProduction() - if debug || os.Getenv("ENV") == "" { +func NewLogger(service string) *zap.Logger { + env := os.Getenv("ENV") + logger, _ := zap.NewProduction(zap.Fields( + zap.String("env", env), + zap.String("service", service), + )) + + if env == "" || env == "development" { logger, _ = zap.NewDevelopment() }