Documentation ¶
Overview ¶
Package placeholders represents a set of placeholders for formatting various log values.
Index ¶
- Constants
- func WithCommonOptions(opts ...options.Option) options.Options
- type CommonPlaceholder
- type InvalidPlaceholderNameError
- type InvalidPlaceholderOptionError
- type Placeholder
- func Field(fieldName string, opts ...options.Option) Placeholder
- func Interval(opts ...options.Option) Placeholder
- func Level(opts ...options.Option) Placeholder
- func Message(opts ...options.Option) Placeholder
- func PlainText(value string, opts ...options.Option) Placeholder
- func Time(opts ...options.Option) Placeholder
- type Placeholders
Constants ¶
const ( WorkDirKeyName = "prefix" DownloadDirKeyName = "download-dir" TFPathKeyName = "tf-path" TFCmdArgsKeyName = "tf-command-args" TFCmdKeyName = "tf-command" )
const IntervalPlaceholderName = "interval"
IntervalPlaceholderName is the placeholder name.
const LevelPlaceholderName = "level"
LevelPlaceholderName is the placeholder name.
const MessagePlaceholderName = "msg"
MessagePlaceholderName is the placeholder name.
const PlainTextPlaceholderName = ""
PlainTextPlaceholderName is the placeholder name.
const TimePlaceholderName = "time"
TimePlaceholderName is the placeholder name. Example `%time()`.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CommonPlaceholder ¶
type CommonPlaceholder struct {
// contains filtered or unexported fields
}
func NewCommonPlaceholder ¶
func NewCommonPlaceholder(name string, opts ...options.Option) *CommonPlaceholder
NewCommonPlaceholder creates a new Common placeholder.
func (*CommonPlaceholder) Format ¶
func (common *CommonPlaceholder) Format(data *options.Data) (string, error)
Format implements `Placeholder` interface.
func (*CommonPlaceholder) Name ¶
func (common *CommonPlaceholder) Name() string
Name implements `Placeholder` interface.
func (*CommonPlaceholder) Options ¶ added in v0.71.2
func (common *CommonPlaceholder) Options() options.Options
Options implements `Placeholder` interface.
type InvalidPlaceholderNameError ¶ added in v0.71.2
type InvalidPlaceholderNameError struct {
// contains filtered or unexported fields
}
InvalidPlaceholderNameError is an invalid `placeholder` name error.
func NewInvalidPlaceholderNameError ¶ added in v0.71.2
func NewInvalidPlaceholderNameError(str string, opts Placeholders) *InvalidPlaceholderNameError
NewInvalidPlaceholderNameError returns a new `InvalidPlaceholderNameError` instance.
func (InvalidPlaceholderNameError) Error ¶ added in v0.71.2
func (err InvalidPlaceholderNameError) Error() string
type InvalidPlaceholderOptionError ¶ added in v0.71.2
type InvalidPlaceholderOptionError struct {
// contains filtered or unexported fields
}
InvalidPlaceholderOptionError is an invalid `placeholder` option error.
func NewInvalidPlaceholderOptionError ¶ added in v0.71.2
func NewInvalidPlaceholderOptionError(ph Placeholder, err error) *InvalidPlaceholderOptionError
NewInvalidPlaceholderOptionError returns a new `InvalidPlaceholderOptionError` instance.
func (InvalidPlaceholderOptionError) Error ¶ added in v0.71.2
func (err InvalidPlaceholderOptionError) Error() string
func (InvalidPlaceholderOptionError) Unwrap ¶ added in v0.71.2
func (err InvalidPlaceholderOptionError) Unwrap() error
type Placeholder ¶
type Placeholder interface { // Name returns a placeholder name. Name() string // Options returns the placeholder options. Options() options.Options // Format returns the formatted value. Format(data *options.Data) (string, error) }
Placeholder is part of the log message, used to format different log values.
func Field ¶
func Field(fieldName string, opts ...options.Option) Placeholder
Field creates a placeholder that displays log field value.
func Interval ¶
func Interval(opts ...options.Option) Placeholder
Interval creates a placeholder that displays seconds that have passed since app started.
func Level ¶
func Level(opts ...options.Option) Placeholder
Level creates a placeholder that displays log level name.
func Message ¶
func Message(opts ...options.Option) Placeholder
Message creates a placeholder that displays log message.
func PlainText ¶
func PlainText(value string, opts ...options.Option) Placeholder
PlainText creates a placeholder that displays plaintext. Although plaintext can be used as is without placeholder, this allows you to format the content, for example set a color: `%(content='just text',color=green)`.
func Time ¶
func Time(opts ...options.Option) Placeholder
Time creates a placeholder that displays log time.
type Placeholders ¶
type Placeholders []Placeholder
Placeholders are a set of Placeholders.
func NewPlaceholderRegister ¶ added in v0.71.2
func NewPlaceholderRegister() Placeholders
NewPlaceholderRegister returns a new `Placeholder` collection instance available for use in a custom format string.
func Parse ¶
func Parse(str string) (Placeholders, error)
Parse parses the given `str` and returns a set of placeholders that are then used to format log data.
func (Placeholders) Format ¶
func (phs Placeholders) Format(data *options.Data) (string, error)
Format returns a formatted string that is the concatenation of the formatted placeholder values.
func (Placeholders) Get ¶
func (phs Placeholders) Get(name string) Placeholder
Get returns the placeholder by its name.
func (Placeholders) Names ¶
func (phs Placeholders) Names() []string
Names returns the names of the placeholders.