-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathfield.go
More file actions
29 lines (24 loc) · 1.08 KB
/
field.go
File metadata and controls
29 lines (24 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package log
import (
"fmt"
"time"
)
// Field is a key-value pair for structured logging.
// This type is backend-agnostic — adapters convert it to their native field type.
type Field struct {
Key string
Value any
}
// Convenience constructors for common field types.
func String(key, value string) Field { return Field{Key: key, Value: value} }
func Int(key string, value int) Field { return Field{Key: key, Value: value} }
func Int64(key string, value int64) Field { return Field{Key: key, Value: value} }
func Float64(key string, value float64) Field { return Field{Key: key, Value: value} }
func Bool(key string, value bool) Field { return Field{Key: key, Value: value} }
func Err(err error) Field { return Field{Key: "error", Value: err} }
func Duration(key string, value time.Duration) Field { return Field{Key: key, Value: value} }
func Any(key string, value any) Field { return Field{Key: key, Value: value} }
// Stringer returns the string representation of a Field.
func (f Field) String() string {
return fmt.Sprintf("%s=%v", f.Key, f.Value)
}