44 "fmt"
55 "io"
66 "runtime"
7+ "time"
78)
89
910type Format func (s fmt.State , verb rune , e Errors )
@@ -20,11 +21,11 @@ func DefaultFormatFn(s fmt.State, verb rune, e Errors) {
2021 _ , _ = io .WriteString (s , "unknown" )
2122 } else {
2223 file , line := fn .FileLine (pc )
23- home , filename := fileName (file )
24+ _ , filename := fileName (file )
2425 if i == 0 {
25- _ , _ = fmt .Fprintf (s , "\t [T] %s\n \t [F] %s\n \t [H] %s \n \t [ F] %s:%d \n " , e .OccurTime ().String ( ), fn .Name (), home , filename , line )
26+ _ , _ = fmt .Fprintf (s , "\t [T] %s\n \t [F] %s\n \t [F] %s:%d \n " , e .OccurTime ().Format ( time . RFC3339 ), fn .Name (), filename , line )
2627 } else {
27- _ , _ = fmt .Fprintf (s , "\t [F] %s\n \t [H] %s \n \t [ F] %s:%d \n " , fn .Name (), home , filename , line )
28+ _ , _ = fmt .Fprintf (s , "\t [F] %s\n \t [F] %s:%d \n " , fn .Name (), filename , line )
2829 }
2930 }
3031 }
@@ -38,18 +39,18 @@ func DefaultFormatFn(s fmt.State, verb rune, e Errors) {
3839 }
3940 case s .Flag ('-' ):
4041 _ , _ = io .WriteString (s , "{" )
41- _ , _ = fmt .Fprintf (s , `"msg":"%s", "occurTime":"%s", "stack":[` , e .Error (), e .OccurTime ())
42+ _ , _ = fmt .Fprintf (s , `"msg":"%s", "occurTime":"%s", "stack":[` , e .Error (), e .OccurTime (). Format ( time . RFC3339 ) )
4243 for i , pc := range e .PCS () {
4344 if i > 0 {
4445 _ , _ = io .WriteString (s , "," )
4546 }
4647 fn := runtime .FuncForPC (pc )
4748 if fn == nil {
48- _ , _ = fmt .Fprintf (s , `{"fn":"%s", "home":"%s", " file":"%s", "line":%d}` , "unknown" , "unknown" , "unknown" , 0 )
49+ _ , _ = fmt .Fprintf (s , `{"fn":"%s", "file":"%s", "line":%d}` , "unknown" , "unknown" , 0 )
4950 } else {
5051 file , line := fn .FileLine (pc )
51- home , filename := fileName (file )
52- _ , _ = fmt .Fprintf (s , `{"fn":"%s", "home":"%s", " file":"%s", "line":%d}` , fn .Name (), home , filename , line )
52+ _ , filename := fileName (file )
53+ _ , _ = fmt .Fprintf (s , `{"fn":"%s", "file":"%s", "line":%d}` , fn .Name (), filename , line )
5354 }
5455 }
5556 _ , _ = io .WriteString (s , "]" )
@@ -75,35 +76,35 @@ func JsonFormatFn(s fmt.State, verb rune, e Errors) {
7576 case 'v' :
7677 switch {
7778 case s .Flag ('+' ):
78- io .WriteString (s , "{" )
79- fmt .Fprintf (s , `"msg":"%s", "occurTime":"%s", "stack":[` , e .Error (), e .OccurTime ())
79+ _ , _ = io .WriteString (s , "{" )
80+ _ , _ = fmt .Fprintf (s , `"msg":"%s", "occurTime":"%s", "stack":[` , e .Error (), e .OccurTime (). Format ( time . RFC3339 ))
8081 for i , pc := range e .PCS () {
8182 if i > 0 {
82- io .WriteString (s , "," )
83+ _ , _ = io .WriteString (s , "," )
8384 }
8485 fn := runtime .FuncForPC (pc )
8586 if fn == nil {
86- fmt .Fprintf (s , `{"fn":"%s", "home":"%s", "file":"%s", "line":%d}` , "unknown" , "unknown" , "unknown" , 0 )
87+ _ , _ = fmt .Fprintf (s , `{"fn":"%s", "home":"%s", "file":"%s", "line":%d}` , "unknown" , "unknown" , "unknown" , 0 )
8788 } else {
8889 file , line := fn .FileLine (pc )
8990 home , filename := fileName (file )
90- fmt .Fprintf (s , `{"fn":"%s", "home":"%s", "file":"%s", "line":%d}` , fn .Name (), home , filename , line )
91+ _ , _ = fmt .Fprintf (s , `{"fn":"%s", "home":"%s", "file":"%s", "line":%d}` , fn .Name (), home , filename , line )
9192 }
9293 }
93- io .WriteString (s , "]" )
94+ _ , _ = io .WriteString (s , "]" )
9495 if e .Cause () != nil {
95- io .WriteString (s , "," )
96+ _ , _ = io .WriteString (s , "," )
9697 hasCause , ok := e .Cause ().(Errors )
9798 if ! ok {
98- fmt .Fprintf (s , `"cause":{"msg":"%s"}` , e .Cause ().Error ())
99+ _ , _ = fmt .Fprintf (s , `"cause":{"msg":"%s"}` , e .Cause ().Error ())
99100 } else {
100- io .WriteString (s , `"cause":` )
101+ _ , _ = io .WriteString (s , `"cause":` )
101102 hasCause .Format (s , verb )
102103 }
103104 }
104- io .WriteString (s , "}" )
105+ _ , _ = io .WriteString (s , "}" )
105106 default :
106- fmt .Fprintf (s , "%s" , e .Error ())
107+ _ , _ = fmt .Fprintf (s , "%s" , e .Error ())
107108 }
108109 }
109110}
0 commit comments