Zap Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Tag: Reverted
Tag: Reverted
Line 11: Line 11:
import "go.uber.org/zap"
import "go.uber.org/zap"


func main() {
...
var config zap.Config
 
var logger *zap.Logger
var config zap.Config
var sugaredLogger *zap.SugaredLogger
var logger *zap.Logger
outputPath := "stderr" // ... or a local path
var sugaredLogger *zap.SugaredLogger
config = zap.NewDevelopmentConfig()
outputPath := "stderr" // ... or a local path
config.OutputPaths = []string{outputPath}
config = zap.NewDevelopmentConfig()
config.ErrorOutputPaths = []string{outputPath}
config.OutputPaths = []string{outputPath}
logger, err := config.Build()
config.ErrorOutputPaths = []string{outputPath}
if err != nil {
logger, err := config.Build()
  panic(err)
if err != nil {
}
  panic(err)
sugaredLogger = logger.Sugar()
sugaredLogger.Infof("somehting")
}
}
sugaredLogger = logger.Sugar()
sugaredLogger.Infof("somehting")


</syntaxhighlight>
</syntaxhighlight>

Revision as of 19:40, 5 January 2024

Internal

Installation

In the directory that contains go.mod:

go get -u go.uber.org/zap

Typical Usage

import "go.uber.org/zap"

...

var config zap.Config
var logger *zap.Logger
var sugaredLogger *zap.SugaredLogger
outputPath := "stderr" // ... or a local path
config = zap.NewDevelopmentConfig()
config.OutputPaths = []string{outputPath}
config.ErrorOutputPaths = []string{outputPath}
logger, err := config.Build()
if err != nil {
  panic(err)
}
sugaredLogger = logger.Sugar()
sugaredLogger.Infof("somehting")