mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-25 21:27:42 +00:00
more logging things
This commit is contained in:
parent
ff9e32ef20
commit
bcce102388
4 changed files with 12 additions and 6 deletions
|
@ -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()
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue