update to github.com/sirupsen/logrus v1.0.0
Signed-off-by: Andrew Pennebaker <apennebaker@datapipe.com>
This commit is contained in:
		 Andrew Pennebaker
					Andrew Pennebaker
				
			
				
					committed by
					
						 Derek McGowan
						Derek McGowan
					
				
			
			
				
	
			
			
			 Derek McGowan
						Derek McGowan
					
				
			
						parent
						
							dd7642fc1c
						
					
				
				
					commit
					1d2a079f08
				
			
							
								
								
									
										74
									
								
								vendor/github.com/sirupsen/logrus/json_formatter.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								vendor/github.com/sirupsen/logrus/json_formatter.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,74 @@ | ||||
| package logrus | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| ) | ||||
|  | ||||
| type fieldKey string | ||||
| type FieldMap map[fieldKey]string | ||||
|  | ||||
| const ( | ||||
| 	FieldKeyMsg   = "msg" | ||||
| 	FieldKeyLevel = "level" | ||||
| 	FieldKeyTime  = "time" | ||||
| ) | ||||
|  | ||||
| func (f FieldMap) resolve(key fieldKey) string { | ||||
| 	if k, ok := f[key]; ok { | ||||
| 		return k | ||||
| 	} | ||||
|  | ||||
| 	return string(key) | ||||
| } | ||||
|  | ||||
| type JSONFormatter struct { | ||||
| 	// TimestampFormat sets the format used for marshaling timestamps. | ||||
| 	TimestampFormat string | ||||
|  | ||||
| 	// DisableTimestamp allows disabling automatic timestamps in output | ||||
| 	DisableTimestamp bool | ||||
|  | ||||
| 	// FieldMap allows users to customize the names of keys for various fields. | ||||
| 	// As an example: | ||||
| 	// formatter := &JSONFormatter{ | ||||
| 	//   	FieldMap: FieldMap{ | ||||
| 	// 		 FieldKeyTime: "@timestamp", | ||||
| 	// 		 FieldKeyLevel: "@level", | ||||
| 	// 		 FieldKeyMsg: "@message", | ||||
| 	//    }, | ||||
| 	// } | ||||
| 	FieldMap FieldMap | ||||
| } | ||||
|  | ||||
| func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { | ||||
| 	data := make(Fields, len(entry.Data)+3) | ||||
| 	for k, v := range entry.Data { | ||||
| 		switch v := v.(type) { | ||||
| 		case error: | ||||
| 			// Otherwise errors are ignored by `encoding/json` | ||||
| 			// https://github.com/sirupsen/logrus/issues/137 | ||||
| 			data[k] = v.Error() | ||||
| 		default: | ||||
| 			data[k] = v | ||||
| 		} | ||||
| 	} | ||||
| 	prefixFieldClashes(data) | ||||
|  | ||||
| 	timestampFormat := f.TimestampFormat | ||||
| 	if timestampFormat == "" { | ||||
| 		timestampFormat = DefaultTimestampFormat | ||||
| 	} | ||||
|  | ||||
| 	if !f.DisableTimestamp { | ||||
| 		data[f.FieldMap.resolve(FieldKeyTime)] = entry.Time.Format(timestampFormat) | ||||
| 	} | ||||
| 	data[f.FieldMap.resolve(FieldKeyMsg)] = entry.Message | ||||
| 	data[f.FieldMap.resolve(FieldKeyLevel)] = entry.Level.String() | ||||
|  | ||||
| 	serialized, err := json.Marshal(data) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err) | ||||
| 	} | ||||
| 	return append(serialized, '\n'), nil | ||||
| } | ||||
		Reference in New Issue
	
	Block a user