fields.go
package logger import ( "github.com/valyala/bytebufferpool") // Fields was slice format of Fieldstype Fields []Field // SetField will add a new fields fieldfunc (f *Fields) SetField(fields ...Field) *Fields { *f = append(*f, fields...) return f} // Add will guess and add value to the fieldsfunc (f *Fields) Add(name string, value interface{}) *Fields { return f.SetField(Any(name, value))} // Skip will add skip field to fieldsfunc (f *Fields) Skip(name string, value string) *Fields { return f.SetField(Skip(name, value))} // Binary will add binary field to fieldsfunc (f *Fields) Binary(name string, value []byte) *Fields { return f.SetField(Binary(name, value))} // ByteString will add byteString field to fieldsfunc (f *Fields) ByteString(name string, value []byte) *Fields { return f.SetField(ByteString(name, value))} exported method Fields.StringTo should have comment or be unexportedfunc (f *Fields) StringTo(byteBuffer *bytebufferpool.ByteBuffer) { if len(*f) == 0 { byteBuffer.WriteString(" ") return } first := true for _, field := range *f { if !first { byteBuffer.WriteString(" ") } byteBuffer.WriteString("<") byteBuffer.WriteString(field.Name) byteBuffer.WriteString(":") byteBuffer.WriteString(field.String()) byteBuffer.WriteString(">") first = false } return} // String will return Fields as stringfunc (f *Fields) String() string { byteBuffer := bytebufferpool.Get() defer bytebufferpool.Put(byteBuffer) f.StringTo(byteBuffer) return byteBuffer.String()} // GoString was called by fmt.Printf("%#v", Fields)// fmt GoStringer interfacefunc (f *Fields) GoString() string { byteBuffer := bytebufferpool.Get() defer bytebufferpool.Put(byteBuffer) byteBuffer.WriteString("logger.Fields[") f.StringTo(byteBuffer) byteBuffer.WriteString("]") return byteBuffer.String()} // NewFields will create a Fields collection with initial valuefunc NewFields(name string, value interface{}) *Fields { return (&Fields{}).Add(name, value)}