options

package
v0.70.2 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package options represents a set of placeholders options.

Index

Constants

View Source
const (
	DateTime    = "date-time"
	DateOnly    = "date-only"
	TimeOnly    = "time-only"
	RFC3339     = "rfc3339"
	RFC3339Nano = "rfc3339-nano"

	Hour24Zero     = "H"
	Hour12Zero     = "h"
	Hour12         = "g"
	MinZero        = "i"
	SecZero        = "s"
	MilliSec       = "v"
	MicroSec       = "u"
	YearFull       = "Y"
	Year           = "y"
	MonthNumZero   = "m"
	MonthNum       = "n"
	MonthText      = "M"
	DayZero        = "d"
	Day            = "j"
	DayText        = "D"
	PMUpper        = "A"
	PMLower        = "a"
	TZText         = "T"
	TZNumWithColon = "P"
	TZNum          = "O"
)
View Source
const AlignOptionName = "align"

AlignOptionName is the option name.

View Source
const CaseOptionName = "case"

CaseOptionName is the option name.

View Source
const ColorOptionName = "color"

ColorOptionName is the option name.

View Source
const ContentOptionName = "content"

ContentOptionName is the option name.

View Source
const EscapeOptionName = "escape"

EscapeOptionName is the option name.

View Source
const LevelFormatOptionName = "format"

LevelFormatOptionName is the option name.

View Source
const PathFormatOptionName = "path"

PathFormatOptionName is the option name.

View Source
const PrefixOptionName = "prefix"

PrefixOptionName is the option name.

View Source
const SuffixOptionName = "suffix"

SuffixOptionName is the option name.

View Source
const TimeFormatOptionName = "format"

TimeFormatOptionName is the option name.

View Source
const WidthOptionName = "width"

WidthOptionName is the option name.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlignOption

type AlignOption struct {
	*CommonOption[AlignValue]
}

func (*AlignOption) Format

func (option *AlignOption) Format(_ *Data, val any) (any, error)

Format implements `Option` interface.

type AlignValue

type AlignValue byte
const (
	NoneAlign AlignValue = iota
	LeftAlign
	CenterAlign
	RightAlign
)

type CaseOption

type CaseOption struct {
	*CommonOption[CaseValue]
}

func (*CaseOption) Format

func (option *CaseOption) Format(_ *Data, val any) (any, error)

Format implements `Option` interface.

type CaseValue

type CaseValue byte
const (
	NoneCase CaseValue = iota
	UpperCase
	LowerCase
	CapitalizeCase
)

type ColorFunc

type ColorFunc func(string) string

type ColorList

type ColorList struct {
	MapValue[ColorValue]
}

func NewColorList

func NewColorList(list map[ColorValue]string) ColorList

func (*ColorList) Parse

func (val *ColorList) Parse(str string) error

func (*ColorList) Set

func (val *ColorList) Set(v ColorValue) *ColorList

type ColorOption

type ColorOption struct {
	*CommonOption[ColorValue]
	// contains filtered or unexported fields
}

func (*ColorOption) Format

func (color *ColorOption) Format(data *Data, val any) (any, error)

Format implements `Option` interface.

type ColorScheme

type ColorScheme map[ColorValue]ColorStyle

func (ColorScheme) Compile

func (scheme ColorScheme) Compile() compiledColorScheme

type ColorStyle

type ColorStyle string

func (ColorStyle) ColorFunc

func (val ColorStyle) ColorFunc() ColorFunc

type ColorValue

type ColorValue int
const (
	NoneColor ColorValue = iota + 255
	DisableColor
	GradientColor
	PresetColor

	BlackColor
	RedColor
	WhiteColor
	YellowColor
	GreenColor
	BlueColor
	CyanColor
	MagentaColor

	LightBlueColor
	LightBlackColor
	LightRedColor
	LightGreenColor
	LightYellowColor
	LightMagentaColor
	LightCyanColor
	LightWhiteColor
)

type CommonOption

type CommonOption[T comparable] struct {
	// contains filtered or unexported fields
}

func NewCommonOption

func NewCommonOption[T comparable](name string, value OptionValue[T]) *CommonOption[T]

NewCommonOption creates a new Common option.

func (*CommonOption[T]) Format

func (option *CommonOption[T]) Format(_ *Data, str string) (string, error)

Format implements `Option` interface.

func (*CommonOption[T]) Name

func (option *CommonOption[T]) Name() string

Name implements `Option` interface.

func (*CommonOption[T]) ParseValue

func (option *CommonOption[T]) ParseValue(str string) error

ParseValue implements `Option` interface.

func (*CommonOption[T]) String

func (option *CommonOption[T]) String() string

String implements `fmt.Stringer` interface.

type ContentOption

type ContentOption struct {
	*CommonOption[string]
}

func (*ContentOption) Format

func (option *ContentOption) Format(_ *Data, val any) (any, error)

Format implements `Option` interface.

type Data

type Data struct {
	*log.Entry
	BaseDir        string
	DisableColors  bool
	RelativePather *RelativePather
	PresetColorFn  func() ColorValue
}

Data is a log entry data.

type EscapeOption

type EscapeOption struct {
	*CommonOption[EscapeValue]
}

func (*EscapeOption) Format

func (option *EscapeOption) Format(_ *Data, val any) (any, error)

Format implements `Option` interface.

type EscapeValue

type EscapeValue byte
const (
	NoneEscape EscapeValue = iota
	JSONEscape
)

type IntValue

type IntValue int

func NewIntValue

func NewIntValue(val int) *IntValue

func (*IntValue) Get

func (val *IntValue) Get() int

func (*IntValue) Parse

func (val *IntValue) Parse(str string) error

type LevelFormatOption

type LevelFormatOption struct {
	*CommonOption[LevelFormatValue]
}

func (*LevelFormatOption) Format

func (format *LevelFormatOption) Format(data *Data, _ any) (any, error)

Format implements `Option` interface.

type LevelFormatValue

type LevelFormatValue byte
const (
	LevelFormatFull LevelFormatValue = iota
	LevelFormatShort
	LevelFormatTiny
)

type MapValue

type MapValue[T comparable] struct {
	// contains filtered or unexported fields
}

func NewMapValue

func NewMapValue[T comparable](list map[T]string) MapValue[T]

func (*MapValue[T]) Filter

func (val *MapValue[T]) Filter(vals ...T) MapValue[T]

func (*MapValue[T]) Get

func (val *MapValue[T]) Get() T

func (*MapValue[T]) Parse

func (val *MapValue[T]) Parse(str string) error

func (MapValue[T]) Set

func (val MapValue[T]) Set(v T) *MapValue[T]

type Option

type Option interface {
	// Name returns the name of the option.
	Name() string
	// Format formats the given string.
	Format(data *Data, val any) (any, error)
	// ParseValue parses and sets the value of the option.
	ParseValue(str string) error
}

Option represents a value modifier of placeholders.

func Align

func Align(value AlignValue) Option

Align creates the option to align text relative to the edges.

func Case

func Case(value CaseValue) Option

Case creates the option to change the case of text.

func Color

func Color(val ColorValue) Option

Color creates the option to change the color of text.

func Content

func Content(val string) Option

Content creates the option that sets the content.

func Escape

func Escape(val EscapeValue) Option

Escape creates the option to escape text.

func LevelFormat

func LevelFormat(val LevelFormatValue) Option

LevelFormat creates the option to format level name.

func PathFormat

func PathFormat(val PathFormatValue, allowed ...PathFormatValue) Option

PathFormat creates the option to format the paths.

func Prefix

func Prefix(val string) Option

Prefix creates the option to add a prefix to the text.

func Suffix

func Suffix(val string) Option

Suffix creates the option to add a suffix to the text.

func TimeFormat

func TimeFormat(val string) Option

func Width

func Width(val int) Option

Width creates the option to set the column width.

type OptionValue

type OptionValue[T any] interface {
	// Parse parses and sets the value of the option.
	Parse(str string) error
	// Get returns the value of the option.
	Get() T
}

OptionValue contains the value of the option.

type Options

type Options []Option

Options is a set of Options.

func (Options) Format

func (opts Options) Format(data *Data, val any) (string, error)

Format returns the formatted value.

func (Options) Get

func (opts Options) Get(name string) Option

Get returns the option with the given name.

func (Options) Merge

func (opts Options) Merge(withOpts ...Option) Options

Merge replaces options with the same name and adds new ones to the end.

func (Options) Names

func (opts Options) Names() []string

Names returns names of the options.

type PathFormatOption

type PathFormatOption struct {
	*CommonOption[PathFormatValue]
}

func (*PathFormatOption) Format

func (option *PathFormatOption) Format(data *Data, val any) (any, error)

Format implements `Option` interface.

type PathFormatValue

type PathFormatValue byte
const (
	NonePath PathFormatValue = iota
	RelativePath
	ShortRelativePath
	ShortPath
	FilenamePath
	DirectoryPath
)

type PrefixOption

type PrefixOption struct {
	*CommonOption[string]
}

func (*PrefixOption) Format

func (option *PrefixOption) Format(_ *Data, val any) (any, error)

Format implements `Option` interface.

type RelativePather

type RelativePather struct {
	// contains filtered or unexported fields
}

RelativePather replaces absolute paths with relative ones, For better performance, during instance creation, we creating a cache of relative paths for each subdirectory of baseDir.

Example of cache: /path/to/dir ./ /path/to ../ /path ../..

func NewRelativePather

func NewRelativePather(baseDir string) (*RelativePather, error)

NewRelativePather returns a new RelativePather instance. It returns an error if the cache of relative paths could not be created for the given `baseDir`.

func (*RelativePather) ReplaceAbsPaths

func (hook *RelativePather) ReplaceAbsPaths(str string) string

type StringValue

type StringValue string

func NewStringValue

func NewStringValue(val string) *StringValue

func (*StringValue) Get

func (val *StringValue) Get() string

func (*StringValue) Parse

func (val *StringValue) Parse(str string) error

type SuffixOption

type SuffixOption struct {
	*CommonOption[string]
}

func (*SuffixOption) Format

func (option *SuffixOption) Format(_ *Data, val any) (any, error)

Format implements `Option` interface.

type TimeFormatOption

type TimeFormatOption struct {
	*CommonOption[string]
}

func (*TimeFormatOption) Format

func (option *TimeFormatOption) Format(data *Data, _ any) (any, error)

Format implements `Option` interface.

type TimeFormatValue

type TimeFormatValue struct {
	MapValue[string]
}

func NewTimeFormatValue

func NewTimeFormatValue(list map[string]string) *TimeFormatValue

func (*TimeFormatValue) Parse

func (val *TimeFormatValue) Parse(str string) error

func (TimeFormatValue) Set

func (TimeFormatValue) SortedKeys

func (val TimeFormatValue) SortedKeys() []string

func (TimeFormatValue) Value

func (val TimeFormatValue) Value(str string) string

type WidthOption

type WidthOption struct {
	*CommonOption[int]
}

func (*WidthOption) Format

func (option *WidthOption) Format(_ *Data, val any) (any, error)

Format implements `Option` interface.

Jump to

Keyboard shortcuts

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