@@ -42,27 +42,41 @@ func TestDebug(t *testing.T) {
4242
4343 d .Debug (testMessage )
4444
45- assert .True (t , hasANSI (buf .String ()), "Must have no colors" )
45+ assert .True (t , hasANSI (buf .String ()))
4646
4747 output := strings .TrimSpace (stripANSI (buf .String ())) // Strip colors and trim whitespace
4848 expected := strings .TrimSpace (testMessageExpected )
49- assert .Equal (t , expected , output , "Must have no colors" )
49+ assert .Equal (t , expected , output )
5050}
5151
52- func TestDebugWithFields (t * testing.T ) {
52+ func TestDebugJSON (t * testing.T ) {
5353 var buf bytes.Buffer
5454 d := getDebugger ()
5555 d .SetOutput (& buf )
56+ SetFormat (JSON )
57+ d .Debug (testMessage )
58+ SetFormat (Plain )
5659
57- x := d .With ("key1" , "value1" ).With ("key2" , 42 )
58-
59- x .Debug (testMessage )
60+ assert .False (t , hasANSI (buf .String ()))
61+ output := strings .TrimSpace (stripANSI (buf .String ())) // Strip colors and trim whitespace
62+ expected := strings .TrimSpace ("{\" namespace\" :\" " + namespace + "\" ,\" message\" :\" " + testMessage + "\" }" )
63+ assert .Equal (t , expected , output )
64+ }
6065
61- assert .True (t , hasANSI (buf .String ()), "Must have no colors" )
66+ func TestDebugJSONWithTimestamp (t * testing.T ) {
67+ var buf bytes.Buffer
68+ d := getDebugger ()
69+ SetOutput (& buf )
70+ SetTimestamp (& Timestamp {Format : "2006" })
71+ SetFormat (JSON )
72+ d .Debug (testMessage )
73+ SetFormat (Plain )
74+ SetTimestamp (nil )
6275
76+ assert .False (t , hasANSI (buf .String ()))
6377 output := strings .TrimSpace (stripANSI (buf .String ())) // Strip colors and trim whitespace
64- expected := strings .TrimSpace (fmt .Sprintf ( "%s key1=value1 key2=42 %s +0ms \n " , namespace , testMessage ) )
65- assert .Equal (t , expected , output , "Must have fields" )
78+ expected := strings .TrimSpace ("{ \" timestamp \" : \" " + fmt .Sprint ( time . Now (). Year ()) + " \" , \" namespace \" : \" " + namespace + " \" , \" message \" : \" " + testMessage + " \" }" )
79+ assert .Equal (t , expected , output )
6680}
6781
6882func TestDebugGlobalOutput (t * testing.T ) {
@@ -74,11 +88,11 @@ func TestDebugGlobalOutput(t *testing.T) {
7488
7589 d .Debug (testMessage )
7690
77- assert .True (t , hasANSI (buf .String ()), "Must have no colors" )
91+ assert .True (t , hasANSI (buf .String ()))
7892
7993 output := strings .TrimSpace (stripANSI (buf .String ())) // Strip colors and trim whitespace
8094 expected := strings .TrimSpace (testMessageExpected )
81- assert .Equal (t , expected , output , "Must have no colors" )
95+ assert .Equal (t , expected , output )
8296}
8397
8498func TestDebugNoColors (t * testing.T ) {
@@ -89,7 +103,7 @@ func TestDebugNoColors(t *testing.T) {
89103
90104 d .Debug (testMessage )
91105
92- assert .False (t , hasANSI (buf .String ()), "Must have no colors" )
106+ assert .False (t , hasANSI (buf .String ()))
93107}
94108
95109func TestDebugNonMatchingNamespace (t * testing.T ) {
@@ -100,7 +114,7 @@ func TestDebugNonMatchingNamespace(t *testing.T) {
100114
101115 d .Debug ("" )
102116
103- assert .Empty (t , buf .String (), "Must have no message" )
117+ assert .Empty (t , buf .String ())
104118}
105119
106120func TestDebugEmptyMessage (t * testing.T ) {
@@ -112,7 +126,7 @@ func TestDebugEmptyMessage(t *testing.T) {
112126 SetNamespace ("does:not:exist" )
113127 d .Debug ("test" )
114128
115- assert .Empty (t , buf .String (), "Must have no message" )
129+ assert .Empty (t , buf .String ())
116130}
117131
118132func TestDebugWithColors (t * testing.T ) {
@@ -123,7 +137,7 @@ func TestDebugWithColors(t *testing.T) {
123137
124138 d .Debug (testMessage )
125139
126- assert .True (t , hasANSI (buf .String ()), "Must have colors" )
140+ assert .True (t , hasANSI (buf .String ()))
127141}
128142
129143func TestDebugf (t * testing.T ) {
0 commit comments