logger

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

README

go-logger

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Ansi = ansiStyle{}
View Source
var Flag iFlag
View Source
var Level iLevel
View Source
var SimpleFormatter simpleFormatterBuilder = simpleFormatterBuilder{
	// contains filtered or unexported fields
}
View Source
var TerminationCode iTerminationCode

Functions

func AppVersion

func AppVersion() version.Version

func Close

func Close()

func Debug

func Debug(v ...any)

func Debugf

func Debugf(format string, v ...any)

func Debugr

func Debugr(r Record)

func Deprecate

func Deprecate(deprecatedVersion version.Version, removalVersion version.Version, v ...any) (bool, error)

func DeprecateMsg

func DeprecateMsg(deprecatedVersion version.Version, removalVersion version.Version, v ...any) string

func DisableDeprecate

func DisableDeprecate() bool

func DisableLava

func DisableLava() bool

func DisableLogLevels

func DisableLogLevels(options logLevel) bool

func EnableDeprecate

func EnableDeprecate() bool

func EnableLava

func EnableLava() bool

func EnableLogLevels

func EnableLogLevels(options logLevel) bool

func Error

func Error(v ...any)

func Errorf

func Errorf(format string, v ...any)

func Errorr

func Errorr(r Record)

func Fatal

func Fatal(v ...any)

func Fatalf

func Fatalf(format string, v ...any)

func Fatalr

func Fatalr(r Record)

func Info

func Info(v ...any)

func Infof

func Infof(format string, v ...any)

func Infor

func Infor(r Record)

func Lava

func Lava(version version.Version, v ...any) volcano

func LoadEnv

func LoadEnv(logger *dnxLogger)

func LogLevels

func LogLevels() logLevel

func NewClone

func NewClone() *dnxLogger

func NewConfigs

func NewConfigs() *configurations

NewConfigs initializes a new configs instance with default values

func NewDefault

func NewDefault() *dnxLogger

func NewWithEnv

func NewWithEnv() *dnxLogger

func SetLogLevels

func SetLogLevels(options logLevel) bool

func SetMinLogLevel

func SetMinLogLevel(level logLevel) bool

func SetVersion

func SetVersion(version version.Version)

func Warning

func Warning(v ...any)

func Warningf

func Warningf(format string, v ...any)

func Warningr

func Warningr(r Record)

Types

type AnsiCode

type AnsiCode string
const (
	TXT_BLACK   AnsiCode = "30m"
	TXT_RED     AnsiCode = "31m"
	TXT_GREEN   AnsiCode = "32m"
	TXT_YELLOW  AnsiCode = "33m"
	TXT_BLUE    AnsiCode = "34m"
	TXT_MAGENTA AnsiCode = "35m"
	TXT_CYAN    AnsiCode = "36m"
	TXT_WHITE   AnsiCode = "37m"

	BG_BLACK   AnsiCode = "40"
	BG_RED     AnsiCode = "41"
	BG_GREEN   AnsiCode = "42"
	BG_YELLOW  AnsiCode = "43"
	BG_BLUE    AnsiCode = "44"
	BG_MAGENTA AnsiCode = "45"
	BG_CYAN    AnsiCode = "46"
	BG_WHITE   AnsiCode = "47"

	CLR_START AnsiCode = "\033["
	CLR_RESET AnsiCode = "\033[0m"

	CLR_NONE AnsiCode = "" // No format
)

func (AnsiCode) String

func (c AnsiCode) String() string

type AnsiColorScheme

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

AnsiColorScheme implements ColorScheme for ANSI styles It provides a mapping of log levels to ANSI styles for console output. It allows for easy customization of log output colors using identifiers. The default identifiers used are listed here for reference:

  • debug
  • info
  • warning
  • error
  • fatal
  • deprecate
  • deprecate_warning
  • deprecate_error
  • deprecate_fatal
  • deprecate_reason
  • lava
  • lava_hot
  • lava_cold
  • lava_dry
  • time
  • file
  • line
  • version
  • message
  • context-key
  • context-value
  • default (used when no specific style is found)

You may add identifiers as needed for your custom formatters.

func (AnsiColorScheme) GetStyle

func (cs AnsiColorScheme) GetStyle(name string) AnsiStyle

type AnsiStyle

type AnsiStyle struct {
	Background AnsiCode
	Text       AnsiCode
	NoStop     bool
}

func (AnsiStyle) Apply

func (s AnsiStyle) Apply(text string) string

type CloseFunc

type CloseFunc func() error

type ColorScheme

type ColorScheme[S Style] interface {
	GetStyle(name string) S
}

type ConsoleColorFormatterBuilder

type ConsoleColorFormatterBuilder struct {
	// contains filtered or unexported fields
}
var ConsoleColorFormatter ConsoleColorFormatterBuilder = ConsoleColorFormatterBuilder{
	// contains filtered or unexported fields
}

func (ConsoleColorFormatterBuilder) AddColor

func (ConsoleColorFormatterBuilder) BaseFormatter

func (ConsoleColorFormatterBuilder) DefaultColor

func (ConsoleColorFormatterBuilder) New

func (ConsoleColorFormatterBuilder) Next

type ConsoleWriterBuilder

type ConsoleWriterBuilder struct {
	// contains filtered or unexported fields
}
var ConsoleWriter ConsoleWriterBuilder

func (ConsoleWriterBuilder) FormatString

func (b ConsoleWriterBuilder) FormatString(format string) ConsoleWriterBuilder

func (ConsoleWriterBuilder) New

func (b ConsoleWriterBuilder) New() Writer

func (ConsoleWriterBuilder) NewLine

type FileWriterBuilder

type FileWriterBuilder struct {
	// contains filtered or unexported fields
}
var FileWriter FileWriterBuilder

func (FileWriterBuilder) FilePath

func (b FileWriterBuilder) FilePath(path string) FileWriterBuilder

func (FileWriterBuilder) FormatString

func (b FileWriterBuilder) FormatString(format string) FileWriterBuilder

func (FileWriterBuilder) New

func (b FileWriterBuilder) New() Writer

func (FileWriterBuilder) NewLine

type FormatRecord

type FormatRecord struct {
	LogLevel     string
	Time         string
	File         string
	Line         string
	Message      string
	AppVersion   string
	Context      map[string](datatypes.SPair[string])
	ContextBegin string
	ContextEnd   string
}

type Formatter

type Formatter interface {
	Format(original *Record, formatRecord ...*FormatRecord) (string, error)
	Next() Formatter
	SetNext(next Formatter)
}

Formatter interface defines the methods required for custom formatter implementations. This interface also provides a guide on what chained formatters for a correct interaction between them.

type FormatterBase

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

FormatterBase provides a base implementation for the Formatter interface. It includes common formatting methods and a next formatter for chaining. You can use this as a base for your custom formatters to ensure that they implement the Formatter interface correctly. It is not needed if you want to implement a custom formatter.

> Keep in mind the golang method overriding behavior

func (*FormatterBase) DateFormat

func (f *FormatterBase) DateFormat() string

Returns the date format used to represent the time in the log record. Do not confuse with dateFormatString, which is used to "decorate" the time value in the log record.

func (*FormatterBase) DefaultFormat

func (f *FormatterBase) DefaultFormat() string

func (*FormatterBase) FinalString

func (f *FormatterBase) FinalString(original *Record, formatRecord *FormatRecord) string

func (*FormatterBase) Format

func (f *FormatterBase) Format(r *Record, formatRecord ...*FormatRecord) (string, error)

Since go does not support method overriding the same way as other languages, if you "override" any of the methods in FormatterBase, you must also override the Format method to ensure that the correct methods are used. If you want to keep this behavior, you can simply copy this method and paste it in your custom formatter implementation, this will ensure that the methods called are the ones you defined in your custom formatter.

func (*FormatterBase) Next

func (f *FormatterBase) Next() Formatter

func (*FormatterBase) SetNext

func (f *FormatterBase) SetNext(next Formatter)

type FormatterBuilder

type FormatterBuilder interface {
	Next(Formatter) FormatterBuilder
	New() Formatter
}

type Record

type Record struct {
	LogLevel   logLevel
	Time       time.Time
	Message    string
	File       string
	Line       int
	AppVersion version.Version
	Context    map[string]string
}

func NewRecord

func NewRecord(msg string, extra ...datatypes.SPair[string]) Record

type Style

type Style interface {
	Apply(text string) string
}

type Writer

type Writer interface {
	CreationError() error
	Write(text string) error
	Close() error
}

type WriterBuilder

type WriterBuilder interface {
	New() Writer
}

Jump to

Keyboard shortcuts

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