-
Notifications
You must be signed in to change notification settings - Fork 63
/
transcript_logger.go
74 lines (59 loc) · 1.67 KB
/
transcript_logger.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2020-2023 the Pinniped contributors. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package testutil
import (
"fmt"
"sync"
"testing"
"github.com/go-logr/logr"
)
type TranscriptLogger struct {
t *testing.T
lock sync.Mutex
transcript []TranscriptLogMessage
}
var _ logr.LogSink = &TranscriptLogger{}
type TranscriptLogMessage struct {
Level string
Message string
}
// Deprecated: Use plog.TestLogger or plog.TestZapr instead. This is meant for old tests only.
func NewTranscriptLogger(t *testing.T) *TranscriptLogger {
return &TranscriptLogger{t: t}
}
func (log *TranscriptLogger) Transcript() []TranscriptLogMessage {
log.lock.Lock()
defer log.lock.Unlock()
result := make([]TranscriptLogMessage, 0, len(log.transcript))
result = append(result, log.transcript...)
return result
}
func (log *TranscriptLogger) Info(_level int, msg string, keysAndValues ...interface{}) {
log.lock.Lock()
defer log.lock.Unlock()
log.transcript = append(log.transcript, TranscriptLogMessage{
Level: "info",
Message: fmt.Sprintf(msg, keysAndValues...),
})
}
func (log *TranscriptLogger) Error(_ error, msg string, _ ...interface{}) {
log.lock.Lock()
defer log.lock.Unlock()
log.transcript = append(log.transcript, TranscriptLogMessage{
Level: "error",
Message: msg,
})
}
func (log *TranscriptLogger) Enabled(_level int) bool {
return true
}
func (log *TranscriptLogger) V(_ int) logr.LogSink {
return log
}
func (log *TranscriptLogger) WithName(_ string) logr.LogSink {
return log
}
func (log *TranscriptLogger) WithValues(_ ...interface{}) logr.LogSink {
return log
}
func (log *TranscriptLogger) Init(_info logr.RuntimeInfo) {}