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