@@ -14,102 +14,24 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17+ // Package testing provides support for using logr in tests.
18+ // Deprecated. See github.com/go-logr/logr/testr instead.
1719package testing
1820
19- import (
20- "testing"
21-
22- "github.com/go-logr/logr"
23- "github.com/go-logr/logr/funcr"
24- )
21+ import "github.com/go-logr/logr/testr"
2522
2623// NewTestLogger returns a logr.Logger that prints through a testing.T object.
27- // Info logs are only enabled at V(0).
28- func NewTestLogger (t * testing.T ) logr.Logger {
29- l := & testlogger {
30- Formatter : funcr .NewFormatter (funcr.Options {}),
31- t : t ,
32- }
33- return logr .New (l )
34- }
24+ // Deprecated. See github.com/go-logr/logr/testr.New instead.
25+ var NewTestLogger = testr .New
3526
3627// Options carries parameters which influence the way logs are generated.
37- type Options struct {
38- // LogTimestamp tells the logger to add a "ts" key to log
39- // lines. This has some overhead, so some users might not want
40- // it.
41- LogTimestamp bool
42-
43- // Verbosity tells the logger which V logs to be write.
44- // Higher values enable more logs.
45- Verbosity int
46- }
28+ // Deprecated. See github.com/go-logr/logr/testr.Options instead.
29+ type Options = testr.Options
4730
4831// NewTestLoggerWithOptions returns a logr.Logger that prints through a testing.T object.
49- // In contrast to the simpler NewTestLogger, output formatting can be configured.
50- func NewTestLoggerWithOptions (t * testing.T , opts Options ) logr.Logger {
51- l := & testlogger {
52- Formatter : funcr .NewFormatter (funcr.Options {
53- LogTimestamp : opts .LogTimestamp ,
54- Verbosity : opts .Verbosity ,
55- }),
56- t : t ,
57- }
58- return logr .New (l )
59- }
60-
61- // Underlier exposes access to the underlying testing.T instance. Since
62- // callers only have a logr.Logger, they have to know which
63- // implementation is in use, so this interface is less of an
64- // abstraction and more of a way to test type conversion.
65- type Underlier interface {
66- GetUnderlying () * testing.T
67- }
68-
69- type testlogger struct {
70- funcr.Formatter
71- t * testing.T
72- }
73-
74- func (l testlogger ) WithName (name string ) logr.LogSink {
75- l .Formatter .AddName (name )
76- return & l
77- }
78-
79- func (l testlogger ) WithValues (kvList ... interface {}) logr.LogSink {
80- l .Formatter .AddValues (kvList )
81- return & l
82- }
83-
84- func (l testlogger ) GetCallStackHelper () func () {
85- return l .t .Helper
86- }
87-
88- func (l testlogger ) Info (level int , msg string , kvList ... interface {}) {
89- prefix , args := l .FormatInfo (level , msg , kvList )
90- l .t .Helper ()
91- if prefix != "" {
92- l .t .Logf ("%s: %s" , prefix , args )
93- } else {
94- l .t .Log (args )
95- }
96- }
97-
98- func (l testlogger ) Error (err error , msg string , kvList ... interface {}) {
99- prefix , args := l .FormatError (err , msg , kvList )
100- l .t .Helper ()
101- if prefix != "" {
102- l .t .Logf ("%s: %s" , prefix , args )
103- } else {
104- l .t .Log (args )
105- }
106- }
107-
108- func (l testlogger ) GetUnderlying () * testing.T {
109- return l .t
110- }
32+ // Deprecated. See github.com/go-logr/logr/testr.NewWithOptions instead.
33+ var NewTestLoggerWithOptions = testr .NewWithOptions
11134
112- // Assert conformance to the interfaces.
113- var _ logr.LogSink = & testlogger {}
114- var _ logr.CallStackHelperLogSink = & testlogger {}
115- var _ Underlier = & testlogger {}
35+ // Underlier exposes access to the underlying testing.T instance.
36+ // Deprecated. See github.com/go-logr/logr/testr.Underlier instead.
37+ type Underlier = testr.Underlier
0 commit comments