JSONFormatter formats logs into parsable json
| 22 | |
| 23 | // JSONFormatter formats logs into parsable json |
| 24 | type JSONFormatter struct { |
| 25 | // TimestampFormat sets the format used for marshaling timestamps. |
| 26 | // The format to use is the same than for time.Format or time.Parse from the standard |
| 27 | // library. |
| 28 | // The standard Library already provides a set of predefined format. |
| 29 | TimestampFormat string |
| 30 | |
| 31 | // DisableTimestamp allows disabling automatic timestamps in output |
| 32 | DisableTimestamp bool |
| 33 | |
| 34 | // DisableHTMLEscape allows disabling html escaping in output |
| 35 | DisableHTMLEscape bool |
| 36 | |
| 37 | // DataKey allows users to put all the log entry parameters into a nested dictionary at a given key. |
| 38 | DataKey string |
| 39 | |
| 40 | // FieldMap allows users to customize the names of keys for default fields. |
| 41 | // As an example: |
| 42 | // formatter := &JSONFormatter{ |
| 43 | // FieldMap: FieldMap{ |
| 44 | // FieldKeyTime: "@timestamp", |
| 45 | // FieldKeyLevel: "@level", |
| 46 | // FieldKeyMsg: "@message", |
| 47 | // FieldKeyFunc: "@caller", |
| 48 | // }, |
| 49 | // } |
| 50 | FieldMap FieldMap |
| 51 | |
| 52 | // CallerPrettyfier can be set by the user to modify the content |
| 53 | // of the function and file keys in the json data when ReportCaller is |
| 54 | // activated. If any of the returned value is the empty string the |
| 55 | // corresponding key will be removed from json fields. |
| 56 | CallerPrettyfier func(*runtime.Frame) (function string, file string) |
| 57 | |
| 58 | // PrettyPrint will indent all json logs |
| 59 | PrettyPrint bool |
| 60 | } |
| 61 | |
| 62 | // Format renders a single log entry |
| 63 | func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { |
nothing calls this directly
no outgoing calls
no test coverage detected