more logging things

This commit is contained in:
Andre Medeiros 2022-05-23 14:29:15 -04:00
parent ff9e32ef20
commit bcce102388
4 changed files with 12 additions and 6 deletions

View file

@ -24,7 +24,7 @@ func APICmd(ctx context.Context) *cobra.Command {
port, _ = strconv.Atoi(os.Getenv("PORT")) port, _ = strconv.Atoi(os.Getenv("PORT"))
} }
logger := cmdutil.NewLogger(false) logger := cmdutil.NewLogger("api")
defer func() { _ = logger.Sync() }() defer func() { _ = logger.Sync() }()
statsd, err := cmdutil.NewStatsdClient() statsd, err := cmdutil.NewStatsdClient()

View file

@ -29,7 +29,7 @@ func SchedulerCmd(ctx context.Context) *cobra.Command {
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
Short: "Schedules jobs and runs several maintenance tasks periodically.", Short: "Schedules jobs and runs several maintenance tasks periodically.",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
logger := cmdutil.NewLogger(false) logger := cmdutil.NewLogger("scheduler")
defer func() { _ = logger.Sync() }() defer func() { _ = logger.Sync() }()
statsd, err := cmdutil.NewStatsdClient() statsd, err := cmdutil.NewStatsdClient()

View file

@ -34,7 +34,8 @@ func WorkerCmd(ctx context.Context) *cobra.Command {
return fmt.Errorf("need a queue to work on") 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() }() defer func() { _ = logger.Sync() }()
tag := fmt.Sprintf("worker:%s", queueID) tag := fmt.Sprintf("worker:%s", queueID)

View file

@ -12,9 +12,14 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
func NewLogger(debug bool) *zap.Logger { func NewLogger(service string) *zap.Logger {
logger, _ := zap.NewProduction() env := os.Getenv("ENV")
if debug || os.Getenv("ENV") == "" { logger, _ := zap.NewProduction(zap.Fields(
zap.String("env", env),
zap.String("service", service),
))
if env == "" || env == "development" {
logger, _ = zap.NewDevelopment() logger, _ = zap.NewDevelopment()
} }