@@ -94,6 +94,11 @@ type Options struct {
94
94
// overhead, so some users might not want it.
95
95
LogTimestamp bool
96
96
97
+ // TimestampFormat tells funcr how to render timestamps when LogTimestamp
98
+ // is enabled. If not specified, a default format will be used. For more
99
+ // details, see docs for Go's time.Layout.
100
+ TimestampFormat string
101
+
97
102
// Verbosity tells funcr which V logs to produce. Higher values enable
98
103
// more logs. Info logs at or below this level will be written, while logs
99
104
// above this level will be discarded.
@@ -137,8 +142,6 @@ const (
137
142
Error
138
143
)
139
144
140
- const timestampFmt = "2006-01-02 15:04:05.000000"
141
-
142
145
// fnlogger inherits some of its LogSink implementation from Formatter
143
146
// and just needs to add some glue code.
144
147
type fnlogger struct {
@@ -190,7 +193,12 @@ func NewFormatterJSON(opts Options) Formatter {
190
193
return newFormatter (opts , outputJSON )
191
194
}
192
195
196
+ const defaultTimestampFmt = "2006-01-02 15:04:05.000000"
197
+
193
198
func newFormatter (opts Options , outfmt outputFormat ) Formatter {
199
+ if opts .TimestampFormat == "" {
200
+ opts .TimestampFormat = defaultTimestampFmt
201
+ }
194
202
f := Formatter {
195
203
outputFormat : outfmt ,
196
204
prefix : "" ,
@@ -665,7 +673,7 @@ func (f Formatter) FormatInfo(level int, msg string, kvList []interface{}) (pref
665
673
prefix = ""
666
674
}
667
675
if f .opts .LogTimestamp {
668
- args = append (args , "ts" , time .Now ().Format (timestampFmt ))
676
+ args = append (args , "ts" , time .Now ().Format (f . opts . TimestampFormat ))
669
677
}
670
678
if policy := f .opts .LogCaller ; policy == All || policy == Info {
671
679
args = append (args , "caller" , f .caller ())
@@ -685,7 +693,7 @@ func (f Formatter) FormatError(err error, msg string, kvList []interface{}) (pre
685
693
prefix = ""
686
694
}
687
695
if f .opts .LogTimestamp {
688
- args = append (args , "ts" , time .Now ().Format (timestampFmt ))
696
+ args = append (args , "ts" , time .Now ().Format (f . opts . TimestampFormat ))
689
697
}
690
698
if policy := f .opts .LogCaller ; policy == All || policy == Error {
691
699
args = append (args , "caller" , f .caller ())
0 commit comments