feat(oohelperd): log messages at info level (#896)
We're using a request-specific logger where we also print the ID of the request. This design helps to observe logs produced by concurrent requests. Part of https://github.com/ooni/probe/issues/2183 While there, fix https://github.com/ooni/probe/issues/2241
This commit is contained in:
parent
8ca7645026
commit
4241ee4bc1
11 changed files with 225 additions and 27 deletions
105
internal/cmd/oohelperd/logging_test.go
Normal file
105
internal/cmd/oohelperd/logging_test.go
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/model/mocks"
|
||||
)
|
||||
|
||||
func TestIndexLogger(t *testing.T) {
|
||||
t.Run("Debug", func(t *testing.T) {
|
||||
expected := "<0>antani"
|
||||
base := &mocks.Logger{
|
||||
MockDebug: func(message string) {
|
||||
if message != expected {
|
||||
t.Fatal("unexpected message")
|
||||
}
|
||||
},
|
||||
}
|
||||
logger := &indexLogger{
|
||||
indexstr: "<0>",
|
||||
logger: base,
|
||||
}
|
||||
logger.Debug("antani")
|
||||
})
|
||||
|
||||
t.Run("Info", func(t *testing.T) {
|
||||
expected := "<0>antani"
|
||||
base := &mocks.Logger{
|
||||
MockInfo: func(message string) {
|
||||
if message != expected {
|
||||
t.Fatal("unexpected message")
|
||||
}
|
||||
},
|
||||
}
|
||||
logger := &indexLogger{
|
||||
indexstr: "<0>",
|
||||
logger: base,
|
||||
}
|
||||
logger.Info("antani")
|
||||
})
|
||||
|
||||
t.Run("Warn", func(t *testing.T) {
|
||||
expected := "<0>antani"
|
||||
base := &mocks.Logger{
|
||||
MockWarn: func(message string) {
|
||||
if message != expected {
|
||||
t.Fatal("unexpected message")
|
||||
}
|
||||
},
|
||||
}
|
||||
logger := &indexLogger{
|
||||
indexstr: "<0>",
|
||||
logger: base,
|
||||
}
|
||||
logger.Warn("antani")
|
||||
})
|
||||
|
||||
t.Run("Debugf", func(t *testing.T) {
|
||||
expected := "<0>antani%d"
|
||||
base := &mocks.Logger{
|
||||
MockDebugf: func(format string, v ...any) {
|
||||
if format != expected {
|
||||
t.Fatal("unexpected message")
|
||||
}
|
||||
},
|
||||
}
|
||||
logger := &indexLogger{
|
||||
indexstr: "<0>",
|
||||
logger: base,
|
||||
}
|
||||
logger.Debugf("antani%d", 11)
|
||||
})
|
||||
|
||||
t.Run("Infof", func(t *testing.T) {
|
||||
expected := "<0>antani%d"
|
||||
base := &mocks.Logger{
|
||||
MockInfof: func(format string, v ...any) {
|
||||
if format != expected {
|
||||
t.Fatal("unexpected message")
|
||||
}
|
||||
},
|
||||
}
|
||||
logger := &indexLogger{
|
||||
indexstr: "<0>",
|
||||
logger: base,
|
||||
}
|
||||
logger.Infof("antani%d", 11)
|
||||
})
|
||||
|
||||
t.Run("Warnf", func(t *testing.T) {
|
||||
expected := "<0>antani%d"
|
||||
base := &mocks.Logger{
|
||||
MockWarnf: func(format string, v ...any) {
|
||||
if format != expected {
|
||||
t.Fatal("unexpected message")
|
||||
}
|
||||
},
|
||||
}
|
||||
logger := &indexLogger{
|
||||
indexstr: "<0>",
|
||||
logger: base,
|
||||
}
|
||||
logger.Warnf("antani%d", 11)
|
||||
})
|
||||
}
|
||||
Loading…
Reference in a new issue