field

package
v1.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2023 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContextLogFields = struct{}{}

Functions

func WithContextFields

func WithContextFields(ctx context.Context, fields ...Field) context.Context

WithContextFields appends fields to provided context.

Types

type Field

type Field struct {
	Key   string
	Value any
	// contains filtered or unexported fields
}

Field stores key-value pairs in order to map them into log structure. TODO(Gorkovets Roman): Make Value field for al supported types in order to avoid inappropriate use of any.

func Any

func Any(key string, value any) Field

Any used for storing values of type any.

func Bool

func Bool(key string, value bool) Field

Bool used for storing boolean values.

func Error

func Error(err error) Field

Error used for storing errors. It displays as `{"error": "database error: timeout"}`

func Float added in v1.0.6

func Float[T floats](key string, value T) Field

Float used for storing floating-point values.

func Int

func Int[T integers](key string, value T) Field

Int used for storing integer values.

func JSONEscape added in v1.0.13

func JSONEscape(key string, value []byte) Field

JSONEscape used for storing json string with escaping characters.

func JSONEscapeSecure added in v1.0.13

func JSONEscapeSecure(key string, value []byte) Field

JSONEscapeSecure the same as JSONEscape but also masks the key-value pairs specified in config. Example:

Data = `{\"password\": \"qwerty123\", \"email\": \"[email protected]\"}`

Using PASSWORD label for "password" and EMAIL for "email" we will reach the next result:

Output = `{\"password\": \"*********\", \"email\": \"e******@example.com\"}`

func String

func String(key string, value string) Field

String used for storing string values.

func (*Field) Error added in v1.0.13

func (f *Field) Error() error

Error returns an error field. It's used to store the error occurred while parsing, creating the field.

type Fields

type Fields []Field

Fields alias for []Field as it's more comfortable to use it this way

func FieldsFromCtx

func FieldsFromCtx(ctx context.Context) Fields

FieldsFromCtx extract fields from context. If ctx is nil, use context.Background()

func (Fields) Map

func (fields Fields) Map() map[string]any

Map maps field as key-value pairs in order to satisfy zerolog With() instructions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL