Documentation ¶
Overview ¶
Package logftxt provides logf.Appender and logf.Encoder implementations that output log messages in a textual human-readable form.
Index ¶
- func ListBuiltInThemes() ([]string, error)
- func NewAppender(w io.Writer, options ...AppenderOption) logf.Appender
- func NewEncoder(options ...EncoderOption) logf.Encoder
- type AppenderOption
- type CallerEncodeFunc
- type CallerFormat
- type ColorSetting
- type Config
- type ConfigProvideFunc
- type Domain
- type DurationEncodeFunc
- type DurationFormat
- type DurationOption
- type EncoderOption
- type Environment
- type ErrFileNotFound
- type ErrorEncodeFunc
- type ErrorFormat
- type FS
- type FSOption
- type FlattenObjectsSetting
- type PoolSizeLimit
- type Precision
- type Theme
- type ThemeEnvironmentRef
- type ThemeProvideFunc
- type ThemeRef
- type TimeEncodeFunc
- type TimeValueEncodeFunc
- type TimestampEncodeFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListBuiltInThemes ¶
ListBuiltInThemes returns list of names of all built-in themes.
func NewAppender ¶
func NewAppender(w io.Writer, options ...AppenderOption) logf.Appender
NewAppender returns a new logf.Appender with the given Writer and optional custom configuration.
func NewEncoder ¶
func NewEncoder(options ...EncoderOption) logf.Encoder
NewEncoder constructs a new logf.Encoder that encodes log messages in a human-readable text representation.
Types ¶
type AppenderOption ¶
type AppenderOption interface {
// contains filtered or unexported methods
}
AppenderOption is an optional parameter for NewAppender.
Applicable types: CallerEncodeFunc, ColorSetting, PoolSizeLimit, Config, ConfigProvideFunc, Environment, FSOption, Theme, ThemeProvideFunc, ThemeEnvironmentRef, ThemeRef, FlattenObjectsSetting, TimestampEncodeFunc, TimeValueEncodeFunc, DurationEncodeFunc, ErrorEncodeFunc.
type CallerEncodeFunc ¶
type CallerEncodeFunc func([]byte, logf.EntryCaller) []byte
CallerEncodeFunc is a function that encodes logf.EntryCaller as a text.
func CallerLong ¶
func CallerLong() CallerEncodeFunc
CallerLong returns a CallerEncodeFunc that encodes caller keeping full file path and line number.
func CallerShort ¶
func CallerShort() CallerEncodeFunc
CallerShort returns a CallerEncodeFunc that encodes caller keeping only package name, base filename and line number.
type CallerFormat ¶
type CallerFormat string
CallerFormat defines duration output format.
const ( CallerFormatDefault CallerFormat = "" CallerFormatShort CallerFormat = "short" CallerFormatLong CallerFormat = "long" )
Valid values for CallerFormat.
func (CallerFormat) Validate ¶
func (v CallerFormat) Validate() error
Validate checks whether v has a valid value.
type ColorSetting ¶
type ColorSetting int
ColorSetting allows to explicitly specify preference on using colors and other ANSI SGR escape sequences in output.
const ( ColorAuto ColorSetting = iota ColorNever ColorAlways )
Valid values for ColorSetting.
type Config ¶
type Config struct { Theme ThemeRef `yaml:"theme"` Timestamp struct { Format string `yaml:"format"` } `yaml:"timestamp"` Caller struct { Format CallerFormat `yaml:"format"` } `yaml:"caller"` Values struct { Time struct { Format string `yaml:"format"` } `yaml:"time"` Duration struct { Format DurationFormat `yaml:"format"` Precision Precision `yaml:"precision"` } `yaml:"duration"` Error struct { Format ErrorFormat `yaml:"format"` } `yaml:"error"` } `yaml:"values"` }
Config holds logftxt configuration.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns default built-in configuration.
func LoadConfig ¶
LoadConfig loads configuration file with the given filename.
func ReadConfig ¶
ReadConfig loads configuration from the given reader.
type ConfigProvideFunc ¶
ConfigProvideFunc is a function that provides Config when called. ConfigProvideFunc can return `nil` configuration and `nil` error in case there is no any configuration found at the corresponding source.
func ConfigFromDefaultPath ¶
func ConfigFromDefaultPath(opts ...domainOption) ConfigProvideFunc
ConfigFromDefaultPath returns a ConfigProvideFunc that load configuration from default path that is `~/.config/logftxt/config.yml`. In case there is no such file, `nil` is returned allowing to fallback to other configuration sources.
func ConfigFromEnvironment ¶
func ConfigFromEnvironment(opts ...domainOption) ConfigProvideFunc
ConfigFromEnvironment returns a ConfigProvideFunc that gets configuration filename from environment variable `LOGFTXT_CONFIG`. In case there is no such environment variable, `nil` is returned allowing to fallback to other configuration sources.
type Domain ¶ added in v0.2.0
type Domain interface { Environment() Environment FS() FS // contains filtered or unexported methods }
Domain provides external dependencies.
func DefaultDomain ¶ added in v0.2.0
func DefaultDomain() Domain
DefaultDomain returns a default implementation of Domain that uses operating system bindings as dependencies.
type DurationEncodeFunc ¶
DurationEncodeFunc is a function that encodes time.Duration values into text.
func DurationAsHMS ¶
func DurationAsHMS(options ...DurationOption) DurationEncodeFunc
DurationAsHMS returns a DurationEncodeFunc that encodes time.Duration values as 'HH:MM:SS.sss' where
HH is number of hours (minimum 2 digits), MM is number of minutes (always 2 digits), SS is number of seconds (always 2 digits), sss is fractional part of seconds (depends on Precision option).
func DurationAsSeconds ¶
func DurationAsSeconds(options ...DurationOption) DurationEncodeFunc
DurationAsSeconds returns a DurationEncodeFunc that encodes time.Duration values as floating point number of seconds.
func DurationAsText ¶
func DurationAsText() DurationEncodeFunc
DurationAsText returns a DurationEncodeFunc that encodes time.Duration values as text with dynamic units. For example, it can be '1ms', '1s', '2m32s'.
type DurationFormat ¶
type DurationFormat string
DurationFormat defines duration output format.
const ( DurationFormatDefault DurationFormat = "" DurationFormatDynamic DurationFormat = "dynamic" DurationFormatSeconds DurationFormat = "seconds" DurationFormatHMS DurationFormat = "hms" )
Valid values for DurationFormat.
func (DurationFormat) Validate ¶
func (v DurationFormat) Validate() error
Validate checks whether v has a valid value.
type DurationOption ¶
type DurationOption interface {
// contains filtered or unexported methods
}
DurationOption is an optional parameter for DurationAsSeconds and DurationAsHMS. Implemented by:
- Precision.
type EncoderOption ¶
type EncoderOption interface { AppenderOption // contains filtered or unexported methods }
EncoderOption is an optional parameter for NewEncoder.
Applicable types: CallerEncodeFunc, ColorSetting, PoolSizeLimit, Config, ConfigProvideFunc, Environment, FSOption, Theme, ThemeProvideFunc, ThemeEnvironmentRef, ThemeRef, FlattenObjectsSetting, TimestampEncodeFunc, TimeValueEncodeFunc, DurationEncodeFunc, ErrorEncodeFunc.
type Environment ¶
Environment is an environment variable lookup function.
type ErrFileNotFound ¶
type ErrFileNotFound struct { Filename string // contains filtered or unexported fields }
ErrFileNotFound is an error that is returned in case file is not found.
func (ErrFileNotFound) Is ¶
func (e ErrFileNotFound) Is(err error) bool
Is returns true if e is a sub-class of err.
func (ErrFileNotFound) Unwrap ¶
func (e ErrFileNotFound) Unwrap() error
Unwrap returns original error.
type ErrorEncodeFunc ¶
ErrorEncodeFunc is a function that encodes errors as a text.
func ErrorLong ¶
func ErrorLong() ErrorEncodeFunc
ErrorLong returns an error formatting function that uses "%+v" format and can be used for errors with additional information like those provided by github.com/pkg/errors package.
func ErrorShort ¶
func ErrorShort() ErrorEncodeFunc
ErrorShort returns an error formatting function that just returns error message.
type ErrorFormat ¶
type ErrorFormat string
ErrorFormat defines duration output format.
const ( ErrorFormatDefault ErrorFormat = "" ErrorFormatShort ErrorFormat = "short" ErrorFormatLong ErrorFormat = "long" )
Valid values for ErrorFormat.
func (ErrorFormat) Validate ¶
func (v ErrorFormat) Validate() error
Validate checks whether v has a valid value.
type FSOption ¶
type FSOption struct {
// contains filtered or unexported fields
}
FSOption is an optional parameter created by WithFS that can be used in
- LoadConfig
- ConfigFromEnvironment
- ConfigFromDefaultPath
- LoadTheme
- ThemeFromEnvironment.
type FlattenObjectsSetting ¶ added in v0.6.0
type FlattenObjectsSetting bool
FlattenObjectsSetting tells encoder to flatten or not nested objects when encoding.
func FlattenObjects ¶ added in v0.6.0
func FlattenObjects(flatten bool) FlattenObjectsSetting
FlattenObjects tells encoder wether to flatten nested objects when encoding.
type PoolSizeLimit ¶
type PoolSizeLimit int
PoolSizeLimit limits size of the pool of pre-allocated entry encoders.
type Precision ¶
type Precision int
Precision can be used to specify exact or automatic precision for formatting floating point values.
const PrecisionAuto Precision = -1
PrecisionAuto is a constant that can be used to request automatic precision selection.
func (Precision) MarshalText ¶
MarshalText implements encoding.TextMarshaler interfaces and allows precision to be converted into text.
func (*Precision) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler interfaces and allows precision to be converted from text.
type Theme ¶
type Theme struct {
// contains filtered or unexported fields
}
Theme holds formatting and styling settings.
func LoadBuiltInTheme ¶
LoadBuiltInTheme loads named built-in theme.
func LoadTheme ¶
LoadTheme loads theme from a file defined by the given filename.
If the filename is relative and does not start with `./` or `../` then the file will be searched in `~/.config/logftxt/themes` folder.
To search file relatively current working directory instead, add explicit `./` or `../` prefix.
type ThemeEnvironmentRef ¶ added in v0.2.0
type ThemeEnvironmentRef struct {
// contains filtered or unexported fields
}
ThemeEnvironmentRef is an option that requests to load theme specified by environment variables.
func ThemeFromEnvironment ¶
func ThemeFromEnvironment(opts ...domainOption) ThemeEnvironmentRef
ThemeFromEnvironment returns a ThemeRef that references some theme as defined by the environment variables.
type ThemeProvideFunc ¶
ThemeProvideFunc is a function that provides Theme when called.
ThemeProvideFunc can return `nil` theme and `nil` error meaning there is nothing to provide from its source.
type ThemeRef ¶
type ThemeRef struct {
// contains filtered or unexported fields
}
ThemeRef is a reference to a built-in or external theme. Built-in theme is referenced by '@' prefix following built-in theme name. External theme is referenced by specifying an absolute or relative path to a theme configuration file. Relative path starting with `./` or `../` will request locating the file relatively to the current working directory. Relative path not starting with `./` or `../` will request locating the file relatively to `~/.config/logftxt/themes` directory.
func NewThemeRef ¶
NewThemeRef constructs a new theme reference with the given name and options.
func (ThemeRef) MarshalText ¶
MarshalText implements encoding.TextMarshaler interface.
func (*ThemeRef) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler interface.
type TimeEncodeFunc ¶
TimeEncodeFunc is a function that encodes time.Time into text.
func TimeLayout ¶
func TimeLayout(layout string) TimeEncodeFunc
TimeLayout returns TimeEncodeFunc that encodes time using the given layout.
func (TimeEncodeFunc) TimeValue ¶
func (f TimeEncodeFunc) TimeValue() TimeValueEncodeFunc
TimeValue returns a TimeValueEncodeFunc that encodes time values into text the same way.
func (TimeEncodeFunc) Timestamp ¶
func (f TimeEncodeFunc) Timestamp() TimestampEncodeFunc
Timestamp returns a TimestampEncodeFunc that encodes timestamp into text the same way.
type TimeValueEncodeFunc ¶
type TimeValueEncodeFunc TimeEncodeFunc
TimeValueEncodeFunc is a function that encodes time field values into text.
type TimestampEncodeFunc ¶
type TimestampEncodeFunc TimeEncodeFunc
TimestampEncodeFunc is a function that encodes log message timestamp into text.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
internal
|
|
pkg/cfgdir
Package cfgdir provides helpers for dealing with configuration directories.
|
Package cfgdir provides helpers for dealing with configuration directories. |
pkg/env
Package env provides accessors to the known environment variables.
|
Package env provides accessors to the known environment variables. |
pkg/pathx
Package pathx provides additional utilities for working with paths.
|
Package pathx provides additional utilities for working with paths. |
pkg/quoting
Package quoting provides helpers to determine if a string needs to be quoted.
|
Package quoting provides helpers to determine if a string needs to be quoted. |
pkg/themecfg
Package themecfg defines configuration file format for a logftxt theme.
|
Package themecfg defines configuration file format for a logftxt theme. |
pkg/themecfg/formatting
Package formatting provides formatting configuration section for slogtxt theme configuration.
|
Package formatting provides formatting configuration section for slogtxt theme configuration. |