SetFormatter sets a custom formatter to print the logs. Any custom output writers should be already registered before calling this method. Returns this AccessLog instance. Usage: ac.SetFormatter(&accesslog.JSON{Indent: " "})
(f Formatter)
| 668 | // Usage: |
| 669 | // ac.SetFormatter(&accesslog.JSON{Indent: " "}) |
| 670 | func (ac *AccessLog) SetFormatter(f Formatter) *AccessLog { |
| 671 | if ac.Writer == nil { |
| 672 | panic("accesslog: SetFormatter called with nil Writer") |
| 673 | } |
| 674 | |
| 675 | if f == nil { |
| 676 | return ac |
| 677 | } |
| 678 | |
| 679 | if flusher, ok := ac.formatter.(Flusher); ok { |
| 680 | // PREPEND formatter flushes, they should run before destination's ones. |
| 681 | ac.Flushers = append([]Flusher{flusher}, ac.Flushers...) |
| 682 | } |
| 683 | |
| 684 | // Inject the writer (AccessLog) here, the writer |
| 685 | // is protected with mutex. |
| 686 | f.SetOutput(ac) |
| 687 | |
| 688 | ac.formatter = f |
| 689 | return ac |
| 690 | } |
| 691 | |
| 692 | // AddFields maps one or more log entries with values extracted by the Request Context. |
| 693 | // You can also add fields per request handler, look the `GetFields` package-level function. |