mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-13 07:27:43 +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"))
|
||||
}
|
||||
|
||||
logger := cmdutil.NewLogger(false)
|
||||
logger := cmdutil.NewLogger("api")
|
||||
defer func() { _ = logger.Sync() }()
|
||||
|
||||
statsd, err := cmdutil.NewStatsdClient()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue