Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions log/log.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package log

import (
"fmt"

"go.uber.org/zap"
)

Expand All @@ -20,8 +22,17 @@ func init() {
log = logger.Sugar()
}

// Setup change configuration on application - call ASAP in main after parse args/env.
// Setup changes log configuration for the application.
// Call ASAP in main after parse args/env.
// Unsafe for concurent use.
func Setup(config Config) {
if err := Build(config); err != nil {
panic(err)
}
}

// Build is a panic-free version of Setup.
func Build(config Config) error {
var cfg zap.Config
if config.Debug {
cfg = zap.NewDevelopmentConfig()
Expand All @@ -30,9 +41,10 @@ func Setup(config Config) {
}
logger, err := cfg.Build()
if err != nil {
panic("Unable to create logger")
return fmt.Errorf("logger creation failed: %v", err)
}
log = logger.Sugar()
return nil
}

// Debug uses fmt.Sprint to construct and log a message.
Expand Down