Documentation ¶
Overview ¶
Package options represents a set of placeholders options.
Index ¶
- Constants
- type AlignOption
- type AlignValue
- type CaseOption
- type CaseValue
- type ColorFunc
- type ColorList
- type ColorOption
- type ColorScheme
- type ColorStyle
- type ColorValue
- type CommonOption
- type ContentOption
- type Data
- type EscapeOption
- type EscapeValue
- type IntValue
- type LevelFormatOption
- type LevelFormatValue
- type MapValue
- type Option
- func Align(value AlignValue) Option
- func Case(value CaseValue) Option
- func Color(val ColorValue) Option
- func Content(val string) Option
- func Escape(val EscapeValue) Option
- func LevelFormat(val LevelFormatValue) Option
- func PathFormat(val PathFormatValue, allowed ...PathFormatValue) Option
- func Prefix(val string) Option
- func Suffix(val string) Option
- func TimeFormat(val string) Option
- func Width(val int) Option
- type OptionValue
- type Options
- type PathFormatOption
- type PathFormatValue
- type PrefixOption
- type RelativePather
- type StringValue
- type SuffixOption
- type TimeFormatOption
- type TimeFormatValue
- type WidthOption
Constants ¶
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" )
const AlignOptionName = "align"
AlignOptionName is the option name.
const CaseOptionName = "case"
CaseOptionName is the option name.
const ColorOptionName = "color"
ColorOptionName is the option name.
const ContentOptionName = "content"
ContentOptionName is the option name.
const EscapeOptionName = "escape"
EscapeOptionName is the option name.
const LevelFormatOptionName = "format"
LevelFormatOptionName is the option name.
const PathFormatOptionName = "path"
PathFormatOptionName is the option name.
const PrefixOptionName = "prefix"
PrefixOptionName is the option name.
const SuffixOptionName = "suffix"
SuffixOptionName is the option name.
const TimeFormatOptionName = "format"
TimeFormatOptionName is the option name.
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] }
type AlignValue ¶
type AlignValue byte
const ( NoneAlign AlignValue = iota LeftAlign CenterAlign RightAlign )
type CaseOption ¶
type CaseOption struct { *CommonOption[CaseValue] }
type ColorList ¶
type ColorList struct { MapValue[ColorValue] }
func NewColorList ¶
func NewColorList(list map[ColorValue]string) ColorList
func (*ColorList) Set ¶
func (val *ColorList) Set(v ColorValue) *ColorList
type ColorOption ¶
type ColorOption struct { *CommonOption[ColorValue] // contains filtered or unexported fields }
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] }
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] }
type LevelFormatOption ¶
type LevelFormatOption struct { *CommonOption[LevelFormatValue] }
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]
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 Color ¶
func Color(val ColorValue) Option
Color creates the option to change the color of 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 TimeFormat ¶
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.
type PathFormatOption ¶
type PathFormatOption struct { *CommonOption[PathFormatValue] }
type PathFormatValue ¶
type PathFormatValue byte
const ( NonePath PathFormatValue = iota RelativePath ShortRelativePath ShortPath FilenamePath DirectoryPath )
type PrefixOption ¶
type PrefixOption struct { *CommonOption[string] }
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] }
type TimeFormatOption ¶
type TimeFormatOption struct { *CommonOption[string] }
type TimeFormatValue ¶
func NewTimeFormatValue ¶
func NewTimeFormatValue(list map[string]string) *TimeFormatValue
func (*TimeFormatValue) Parse ¶
func (val *TimeFormatValue) Parse(str string) error
func (TimeFormatValue) Set ¶
func (val TimeFormatValue) Set(v string) *TimeFormatValue
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] }