add logger
This commit is contained in:
parent
38cea96107
commit
a638a63731
1 changed files with 29 additions and 0 deletions
29
pkg/logger/logger.go
Normal file
29
pkg/logger/logger.go
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package logger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"go.uber.org/zap"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Sugar is a global instance of the zap sugared logger.
|
||||||
|
var Sugar *zap.SugaredLogger
|
||||||
|
|
||||||
|
// Init initializes the global logger and returns a cleanup function.
|
||||||
|
// The cleanup function should be deferred in the main function.
|
||||||
|
func Init() func() {
|
||||||
|
// NewProduction builds a sensible production logger that writes InfoLevel and
|
||||||
|
// above logs to standard error.
|
||||||
|
coreLogger, err := zap.NewDevelopment()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("can't initialize zap logger: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assign the sugared logger to our global variable.
|
||||||
|
Sugar = coreLogger.Sugar()
|
||||||
|
|
||||||
|
// Return the Sync function to be deferred by the caller.
|
||||||
|
return func() {
|
||||||
|
_ = coreLogger.Sync()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue