generated from hadenlabs/terraform-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
zap.go
50 lines (42 loc) · 975 Bytes
/
zap.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package provider
import (
"go.uber.org/zap"
"github.com/hadenlabs/terraform-aws-iam-user/config"
)
// Zap is a struct of Zap.
type ZapLog struct {
Client *zap.Logger
}
func NewZap(conf config.Config) *ZapLog {
logger, _ := zap.NewProduction()
defer func() { // flushes buffer, if any
_ = logger.Sync()
}()
return &ZapLog{Client: logger}
}
func (l *ZapLog) Close() {
defer func() { // flushes buffer, if any
_ = l.Client.Sync()
}()
}
// Send an debug.
func (l *ZapLog) Debugf(msg string, args ...interface{}) {
l.Client.Sugar().Debugf(msg, args)
defer func() { // flushes buffer, if any
_ = l.Client.Sync()
}()
}
// Send an infof.
func (l *ZapLog) Infof(msg string, args ...interface{}) {
l.Client.Sugar().Infof(msg, args)
defer func() { // flushes buffer, if any
_ = l.Client.Sync()
}()
}
// Send an error.
func (l *ZapLog) Error(msg string) {
l.Client.Sugar().Error(msg)
defer func() { // flushes buffer, if any
_ = l.Client.Sync()
}()
}