MCPcopy
hub / github.com/rs/zerolog / consoleDefaultFormatTimestamp

Function consoleDefaultFormatTimestamp

console.go:412–454  ·  view source on GitHub ↗
(timeFormat string, location *time.Location, noColor bool)

Source from the content-addressed store, hash-verified

410}
411
412func consoleDefaultFormatTimestamp(timeFormat string, location *time.Location, noColor bool) Formatter {
413 if timeFormat == "" {
414 timeFormat = consoleDefaultTimeFormat
415 }
416 if location == nil {
417 location = time.Local
418 }
419
420 return func(i interface{}) string {
421 t := "<nil>"
422 switch tt := i.(type) {
423 case string:
424 ts, err := time.ParseInLocation(TimeFieldFormat, tt, location)
425 if err != nil {
426 t = tt
427 } else {
428 t = ts.In(location).Format(timeFormat)
429 }
430 case json.Number:
431 i, err := tt.Int64()
432 if err != nil {
433 t = tt.String()
434 } else {
435 var sec, nsec int64
436
437 switch TimeFieldFormat {
438 case TimeFormatUnixNano:
439 sec, nsec = 0, i
440 case TimeFormatUnixMicro:
441 sec, nsec = 0, int64(time.Duration(i)*time.Microsecond)
442 case TimeFormatUnixMs:
443 sec, nsec = 0, int64(time.Duration(i)*time.Millisecond)
444 default:
445 sec, nsec = i, 0
446 }
447
448 ts := time.Unix(sec, nsec)
449 t = ts.In(location).Format(timeFormat)
450 }
451 }
452 return colorize(t, colorDarkGray, noColor)
453 }
454}
455
456func stripLevel(ll string) string {
457 if len(ll) == 0 {

Callers 1

writePartMethod · 0.85

Calls 3

colorizeFunction · 0.85
Int64Method · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…