forked from corazawaf/coraza-caddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger_test.go
41 lines (31 loc) · 877 Bytes
/
logger_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2024 The OWASP Coraza contributors
// SPDX-License-Identifier: Apache-2.0
package coraza
import (
"os"
"testing"
"github.com/corazawaf/coraza/v3/debuglog"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)
func BenchmarkLogger(b *testing.B) {
f, err := os.CreateTemp(b.TempDir(), "test.log")
require.NoError(b, err)
cfg := zap.NewProductionConfig()
cfg.OutputPaths = []string{f.Name()}
l, err := cfg.Build()
require.NoError(b, err)
var (
l1, l2, l3 debuglog.Logger
debugLogger = newLogger(l)
)
b.ResetTimer()
for i := 0; i < b.N; i++ {
l1 = debugLogger.With(debuglog.Str("key1", "value1"))
l1.Info().Msg("message1")
l2 = debugLogger.With(debuglog.Str("key2", "value2"), debuglog.Str("key3", "value3"))
l2.Info().Msg("message2&3")
l3 = debugLogger.With(debuglog.Str("key4", "value4"))
l3.Info().Msg("message4")
}
}