-
hello, I have an implementations that creates a few thousands of logs in a second and Zap seems to print most of them but it misses some, without a pattern, the function is: func (p *Parser) FromString(data string) error {
scanner := bufio.NewScanner(strings.NewReader(data))
var linebuffer = ""
pattern := regexp.MustCompile(`\\(\s+)?$`)
p.Waf.Logger.Debug("do some logging here")
for scanner.Scan() {
p.currentLine++
line := scanner.Text()
linebuffer += strings.TrimSpace(line)
// Check if line ends with \
match := pattern.MatchString(line)
fmt.Println(line)
p.Waf.Logger.Debug("Parsing partial line", zap.String("line", line),
zap.Int("line_number", p.currentLine))
if !match {
err := p.evaluate(linebuffer)
if err != nil {
return err
}
linebuffer = ""
} else {
linebuffer = strings.TrimSuffix(linebuffer, "\\")
}
}
return nil
} No log inside that loop will be generated but every other log will be displayed, also the "do some logging here" debug log will be shown and the fmt.Println(line). There are a few exceptions, somehow it does show logs from inside the loop some times. Here is my zap init code: func (w *Waf) SetDebugLogPath(path string) error {
cfg := zap.NewProductionConfig()
if path == "" {
cfg.OutputPaths = []string{}
} else {
cfg.OutputPaths = []string{"/dev/stdout"}
}
cfg.Level = *w.loggerAtomicLevel
logger, err := cfg.Build()
if err != nil {
return err
}
w.Logger = logger
return nil
} I'm using version v1.19.1 What am I doing wrong :( |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
When the default production config is used, zap does sampling by default. You can disable sampling by setting the sampling policy to nil, cfg := zap.NewProductionConfig()
cfg.Sampling = nil // disable sampling |
Beta Was this translation helpful? Give feedback.
When the default production config is used, zap does sampling by default. You can disable sampling by setting the sampling policy to nil,