Questions tagged [go-zap]

Zap is the logging framework for Go developed by Uber. It offers a powerful API for building structured loggers. Use this tag for questions related to the usage of the zap library in Go.

The package uber-go/zap is a logging framework used to add structured, leveled logging to a Go application.

The most frequently used packages are:

  • zap that contains the main abstractions
  • zapcore that contains the logic and types for constructing bespoke loggers

A simple example of how to use Zap:

logger, _ := zap.NewDevelopment()
logger.Info("hello world", zap.String("foo", "bar"))

Useful packages that extend Zap functionality:

58 questions
1
vote
2 answers

Does Zap logger support escape character '\n' and '\t' to print new line errorVerbose or stacktrace

func InitLogger() { loggerMgr, err := zap.NewProduction() if err != nil { log.Println("error") } defer loggerMgr.Sync() logger := loggerMgr.Sugar() logger.Error("START!") } The…
user1365697
  • 5,819
  • 15
  • 60
  • 96
1
vote
1 answer

How to add a hook into a zap logger?

I try to add hook with WithOptions but there was nothing printed for catching some of log events: logger.WithOptions(zap.Hooks(func(entry zapcore.Entry) error { fmt.Println("test hooks test hooks") return nil }))
Viktor
  • 1,532
  • 6
  • 22
  • 61
1
vote
1 answer

How to use zap logger with go-kit?

I want to use the go-kit logger lib with zap and I want it in this function to return instance of zap.logger that I will be able to use it like following: (using zap functionality) like logger.Info or logger.WithOptions etc I try with the following…
JME
  • 881
  • 2
  • 11
  • 23
1
vote
1 answer

Uber zap logging having custom message encoder

I am using below code to dump logs on console and log file using Uber zap logger. How I can have a custom message encoder so that the output format for the message can be as below? {"severity":"DEBUG","message":"Dec 12, 2018 19:52:39 [log.go:77]…
Abhinav
  • 975
  • 4
  • 18
  • 35
1
vote
2 answers

Zap stack traces vs. error messages on google cloud

I'm using zapp to log error messages on a service hosted on google cloud, and am seeing that while errors are logged successfully, the text stored in the "message" field of the google cloud log is the stack trace, and not the error message I have…
DaveBensonPhillips
  • 3,134
  • 1
  • 20
  • 32
0
votes
0 answers

Add a prefix to zap logger for all message

I had set up the zap logger with the following configuration outLevel := zap.LevelEnablerFunc(func(level zapcore.Level) bool { return level < zapcore.WarnLevel }) // Warnings and everything above will be printed to stderr …
Viren
  • 5,812
  • 6
  • 45
  • 98
0
votes
1 answer

How to elegantly configure a Logger with a configuration file while supporting log rotation

Problem Description Function: Test1() is a log rotation and cutting library gopkg.in/natefinch/lumberjack.v2 recommended in the official documentation. Function: Test2() is a Logger that uses yaml to read configuration based on the basic…
jiaopengzi
  • 11
  • 2
0
votes
1 answer

Zap package in Go prints all logs even I set log level as Debug level

I use zap I've set the log level as a debug level but when I run the application I get all levels. cfg := zap.Config{ Encoding: "json", Level: zap.NewAtomicLevelAt(zapcore.DebugLevel), OutputPaths: …
Marwan Galal
  • 47
  • 1
  • 5
0
votes
1 answer

How to send log to a different location : UberZap

I need to send logs to the different location in go zap logger. How can I do that?
EagerLearner
  • 447
  • 1
  • 5
  • 11
0
votes
2 answers

Zap logger source line

How to print the exact source line using zap. I create a package where it stores variable(zap logger). This global variable will be called inside functions in that package. The problem is it's not printing the actual caller, instead it calls where…
Jake Muller
  • 925
  • 4
  • 18
  • 25
-1
votes
1 answer

How to use ellipsis for zap global logger

Hello I am trying to change sugar logger to global longer I checked possible fields which I can use but I couldn't something solve my problem for example in some situations I use zap.L().Debug("recv_cmd", …
Kufu
  • 49
  • 1
  • 6
-1
votes
1 answer

Zap logger values

Hello I want to use zap global logger right now I am using like this zap.L().Error("error receive", zap.Error(err), zap.String("uuid", msg.Id) zap.String("msg_f", msg_f), ) but the only problem is…
Kufu
  • 49
  • 1
  • 6
-2
votes
1 answer

How to log key/value pairs in Uber Zap without using Fields

I am using zap library for logging and I try some simple scenario in which I want to log several entries without using Fields. Unfortunately it doesn't work. Code cfg := zap.Config{ Encoding: "json", Level: …
Jenny M
  • 923
  • 1
  • 14
  • 37
1 2 3
4