| 410 | } |
| 411 | |
| 412 | func 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 | |
| 456 | func stripLevel(ll string) string { |
| 457 | if len(ll) == 0 { |