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
2
votes
2 answers

Uber Zap logger not printing caller information in the log statement

I am trying to put the same message to console and the log files at the same time with custom encoder for config. In the process I want to display the caller information but the same is not being displayed even if I have used caller key as suggested…
Abhinav
  • 975
  • 4
  • 18
  • 35
1
vote
1 answer

How can I use custom time function in zap logger library

I'm working with the Zap logger library in Go and I'm trying to achieve a custom timestamp generation approach for logging. Specifically, I want to use my own time function instead of relying on the system time. While I've explored the…
Prakash P
  • 3,582
  • 4
  • 38
  • 66
1
vote
0 answers

How to replace using zap logger .With() instead of append

I want to add shared fields to the logger so that subsequent logs will all contain some common fields. There are the options to use (*zap.Logger) With() or (*zap.Logger) WithOptions(zap.Fields). However both append fields instead of replace. I had…
3tbraden
  • 667
  • 1
  • 10
  • 21
1
vote
0 answers

Print only the desired information from the Zap log

I would like to know if there is a method to print only the desired information from a Zap log, with the following…
1
vote
0 answers

Using ecszap logger with Kubernetes controller-runtime

I am wrestling with logging in a Kubernetes operator built with: KubeBuilderVersion: 3.7.0 go version: go1.20.1 linux/amd64 Up and until now, for logging purposes, I have made use of the zap logger package…
Morné Kruger
  • 309
  • 1
  • 12
1
vote
0 answers

aws lambda variable with execution scope in golang

I have a variable for logger in a package main: This is the folder tree directory: cmd: lambda: main.go service: xxxx.go yyyy.go repository: aa_repository.go In my main lambda I have the following code: var ( log…
daocc
  • 47
  • 4
1
vote
1 answer

Zap logger add UUID to all logs in golang

I have this method used in a lambda: import ( "os" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) func InitLogger() *zap.Logger { config := zap.NewProductionEncoderConfig() config.EncodeTime = zapcore.RFC3339TimeEncoder …
daocc
  • 47
  • 4
1
vote
0 answers

How to temporarily disable/mute logging using Zap logger in Go

How to temporarily disable logging using Zap logger in Go. I need to mute logs for a particular function without removing logger print statements. I need a solution similar to what we do for fmt as below, temp := os.Stdout os.Stdout =…
Gopi Kumar
  • 53
  • 5
1
vote
1 answer

Hide sensitive fields in Uber Zap go

Is there any way in which I can hide logging sensitive fields while using ubergo zap. Will appreciate if somebody can show an example
EagerLearner
  • 447
  • 1
  • 5
  • 11
1
vote
1 answer

UberZap with gelf driver writes whole log into message field

I'm using uber-zap for logging and I'm trying to log to graylog in GELF format. Log is written successfully but the whole json is being sent as message key of log record. message:…
Ali Farhoudi
  • 5,350
  • 7
  • 26
  • 44
1
vote
0 answers

Not able to see the logs in Custom Location in Kubernetes

I am using zap as the logger. I am storing the log in the custom location: /var/tmp/audit.log Unfortunately, when I try to look at the logs in Kubernetes I am not able to find those logs. Can anyone suggest what I am missing? Do I have to volume…
EagerLearner
  • 447
  • 1
  • 5
  • 11
1
vote
1 answer

How to send logs to a different location : Kubernetes

So I want to develop multiple flavors of log one for generic use and other for performing a specific operation I want to separate those logs by storing them in a different location and using them for further processing. I can see the logs in…
EagerLearner
  • 447
  • 1
  • 5
  • 11
1
vote
1 answer

How can I duplicate entry keys and show it in the same log with Uber Zap?

I would like to duplicate entry keys like caller with another key name method and show both in the log... {"level":"error", "caller: "testing/testing.go:1193", "method": "testing/testing.go:1193", "message": "foo"} Any ideas?
Victor Godoy
  • 1,642
  • 15
  • 18
1
vote
1 answer

How to properly capture zap logger output in unit tests

Based off the configurations for zap.NewDevelopmentConfig() and zap.NewProductionConfig(), I've assumed that zap writes logs to stderr. However, I can't seem to capture the output in unit tests. I have the following captureOutput func: func…
vercingortix
  • 199
  • 2
  • 15
1
vote
1 answer

How to mock zap logger from ctrl "sigs.k8s.io/controller-runtime"?

package logger import ( "bytes" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ctrl "sigs.k8s.io/controller-runtime" ) var _ = Describe("Logger", func() { It("Test Default Log Level", func() { buf :=…
user1365697
  • 5,819
  • 15
  • 60
  • 96