MCPcopy Create free account
hub / github.com/kataras/iris / SetFormatter

Method SetFormatter

middleware/accesslog/accesslog.go:670–690  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

668// Usage:
669// ac.SetFormatter(&accesslog.JSON{Indent: " "})
670func (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.

Callers 8

registerAccessLoggerMethod · 0.80
mainFunction · 0.80
makeAccessLogFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
benchmarkAccessLogAfterFunction · 0.80
TestCSVFunction · 0.80

Calls 1

SetOutputMethod · 0.65

Tested by 2

benchmarkAccessLogAfterFunction · 0.64
TestCSVFunction · 0.64