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 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" )
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) GetOption ¶
func (common *CommonPlaceholder) GetOption(str string) (options.Option, error)
GetOption implements `Placeholder` interface.
func (*CommonPlaceholder) Name ¶
func (common *CommonPlaceholder) Name() string
Name implements `Placeholder` interface.
type Placeholder ¶
type Placeholder interface { // Name returns a placeholder name. Name() string // GetOption returns the option with the given option name. GetOption(name string) (options.Option, error) // 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 Parse ¶
func Parse(str string) (Placeholders, error)
Parse parses the given string 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.