Field
Field represents a structured key-value pair for logging. Fields are designed to be zero-allocation - they are simple structs that can be created and passed around efficiently. The valueType allows the formatter to handle different types appropriately (e.g., quoting strings, formatting numbers, handling errors specially).Type Definition
Methods
Key
Returns the field’s key. This is useful for formatters and hooks that need to inspect fields.Type
Returns the field’s value type. This is useful for type-specific formatting.FieldType.
Value
Returns the field’s value. This is useful for formatters and hooks that need to access the value.interface{}.
StringValue
Returns the string representation of the field’s value. For non-string types, it returns an empty string.IntValue
Returns the int value. Returns 0 if the field is not an IntType.Int64Value
Returns the int64 value. Returns 0 if the field is not an Int64Type.Float64Value
Returns the float64 value. Returns 0 if the field is not a Float64Type.BoolValue
Returns the bool value. Returns false if the field is not a BoolType.ErrorValue
Returns the error value. Returns nil if the field is not an ErrorType.FieldType
FieldType represents the type of value stored in a Field. This enables type-specific formatting in formatters.Type Definition
Constants
Represents a string value (iota = 0)
Represents an int value
Represents an int64 value
Represents a float64 value
Represents a bool value
Represents an error value (formatted specially)
Represents an arbitrary interface value