ev/internal/logz/init.go

43 lines
739 B
Go
Raw Normal View History

package logz
import (
"context"
"log"
2022-08-14 13:40:02 -06:00
"os"
"go.uber.org/multierr"
)
func Init(ctx context.Context, name string) (context.Context, func() error) {
2022-08-13 18:59:15 -06:00
ctx, span := Span(ctx)
defer span.End()
stop := [3]func() error{
initLogger(name),
}
ctx, stop[1] = initMetrics(ctx, name)
ctx, stop[2] = initTracing(ctx, name)
reverse(stop[:])
return ctx, func() error {
log.Println("flushing logs...")
errs := make([]error, len(stop))
for i, fn := range stop {
2022-08-13 18:59:15 -06:00
if fn != nil {
errs[i] = fn()
}
}
log.Println("all stopped.")
return multierr.Combine(errs...)
}
}
2022-08-14 13:40:02 -06:00
func env(name, defaultValue string) string {
if v := os.Getenv(name); v != "" {
log.Println("# ", name, " = ", v)
return v
}
return defaultValue
}