placeholders

package
v0.70.4 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package placeholders represents a set of placeholders for formatting various log values.

Index

Constants

View Source
const (
	WorkDirKeyName     = "prefix"
	DownloadDirKeyName = "download-dir"
	TFPathKeyName      = "tf-path"
	TFCmdArgsKeyName   = "tf-command-args"
)
View Source
const IntervalPlaceholderName = "interval"

IntervalPlaceholderName is the placeholder name.

View Source
const LevelPlaceholderName = "level"

LevelPlaceholderName is the placeholder name.

View Source
const MessagePlaceholderName = "msg"

MessagePlaceholderName is the placeholder name.

View Source
const PlainTextPlaceholderName = ""

PlainTextPlaceholderName is the placeholder name.

View Source
const TimePlaceholderName = "time"

TimePlaceholderName is the placeholder name. Example `%time()`.

Variables

This section is empty.

Functions

func WithCommonOptions

func WithCommonOptions(opts ...options.Option) options.Options

WithCommonOptions is a set of common options that are used in all placeholders.

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.

Jump to

Keyboard shortcuts

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