generated from Serpentiel/go-cli
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
36 lines (30 loc) · 887 Bytes
/
logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Package provide is the package that contains all of the providers for the dependency injection container.
package provide
import (
"context"
"github.com/Serpentiel/arikawa-boilerplate/pkg/logger"
"github.com/Serpentiel/arikawa-boilerplate/pkg/logger/asynczap"
"github.com/Serpentiel/arikawa-boilerplate/pkg/logger/zap"
"github.com/spf13/viper"
"go.uber.org/fx"
)
// Logger is a function which provides a log.Logger instance.
func Logger(lc fx.Lifecycle, v *viper.Viper) logger.Logger {
l := asynczap.NewAsyncZap(zap.NewZap(
&zap.Params{
Path: v.GetString("logger.path"),
RetainDays: v.GetInt("logger.retain.days"),
RetainCopies: v.GetInt("logger.retain.copies"),
},
))
lc.Append(fx.Hook{
OnStart: func(context.Context) (err error) {
go l.Work()
return
},
OnStop: func(context.Context) error {
return l.Close()
},
})
return l
}