log

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DebugLevel     = charmlog.DebugLevel
	InfoLevel      = charmlog.InfoLevel
	WarnLevel      = charmlog.WarnLevel
	ErrorLevel     = charmlog.ErrorLevel
	FatalLevel     = charmlog.FatalLevel
	ImportantLevel = WarnLevel + 1
)
View Source
const (
	TextFormatter   = charmlog.TextFormatter
	JSONFormatter   = charmlog.JSONFormatter
	LogfmtFormatter = charmlog.LogfmtFormatter
)

Formatters

Variables

View Source
var (
	ShortCallerFormatter = charmlog.ShortCallerFormatter
	LongCallerFormatter  = charmlog.LongCallerFormatter
)

Caller Formatters

Functions

func Debug

func Debug(msg string, args ...any)

Logging methods

func Debugf

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

func Default

func Default() *slog.Logger

Default returns the default logger instance

func Error

func Error(msg string, args ...any)

func Errorf

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

func Fatal

func Fatal(msg any, args ...any)

func Fatalf

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

func Highlight

func Highlight(text string) string

Highlight makes the given text stand out (yello fg and dark bg)

func Important

func Important(msg string, args ...any)

func Importantf

func Importantf(format string, args ...any)

func Info

func Info(msg string, args ...any)

func Infof

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

func LogLevelString

func LogLevelString(l Level) string

LogLevel returns the string representation of the level

func New

func New(opts ...Option) (*slog.Logger, error)

New creates a new logger with the given options

func Reset

func Reset()

Reset resets all global state (useful for testing)

func SetCallerFormatter

func SetCallerFormatter(f CallerFormatter, loggers ...*slog.Logger)

SetCallerFormatter sets the caller formatter.

func SetCallerOffset

func SetCallerOffset(offset int, loggers ...*slog.Logger)

SetCallerOffset sets the caller offset.

func SetFormatter

func SetFormatter(f Formatter, loggers ...*slog.Logger)

SetFormatter sets the formatter.

func SetLevel

func SetLevel(level Level, loggers ...*slog.Logger)

SetLevel sets the level.

func SetOutput

func SetOutput(w io.Writer, loggers ...*slog.Logger)

SetOutput sets the output destination.

func SetPrefix

func SetPrefix(prefix string, loggers ...*slog.Logger)

SetPrefix sets the prefix.

func SetReportCaller

func SetReportCaller(report bool, loggers ...*slog.Logger)

SetReportCaller sets whether to report caller location.

func SetReportTimestamp

func SetReportTimestamp(report bool, loggers ...*slog.Logger)

SetReportTimestamp sets whether to report timestamp.

func SetStyles

func SetStyles(s *Styles, loggers ...*slog.Logger)

SetStyles sets the logger styles.

func SetTimeFormat

func SetTimeFormat(format string, loggers ...*slog.Logger)

SetTimeFormat sets the time format.

func SetTimeFunction

func SetTimeFunction(f TimeFunction, loggers ...*slog.Logger)

SetTimeFunction sets the time function.

func UnderBold

func UnderBold(text string) string

UnderBold makes the given text with an underline and bold

func Warn

func Warn(msg string, args ...any)

func Warnf

func Warnf(format string, args ...any)

func WithPrefix

func WithPrefix(l *slog.Logger, prefix string) *slog.Logger

WithPrefix returns a new logger with the given prefix.

Types

type CallerFormatter

type CallerFormatter = charmlog.CallerFormatter

type Formatter

type Formatter = charmlog.Formatter

type Level

type Level = charmlog.Level

type Logger

type Logger = charmlog.Logger

type Option

type Option func(*Options)

func AsDefault

func AsDefault() Option

func EnableRotation added in v1.5.1

func EnableRotation(maxSize string, maxFiles int) Option

EnableRotation enables log rotation with the specified settings. If the settings are invalid (empty or zero), rotation will be silently disabled.

func UseLevel

func UseLevel(l Level) Option

func UseOutput

func UseOutput(w io.Writer) Option

func UseOutputFunc

func UseOutputFunc(f func() (io.Writer, error)) Option

func UseOutputPath

func UseOutputPath(path string) Option

func UseReportCaller

func UseReportCaller(report bool) Option

func UseReportTimestamp

func UseReportTimestamp(report bool) Option

func UseStyles

func UseStyles(s *Styles) Option

func UseTimeFormat

func UseTimeFormat(format string) Option

type Options

type Options struct {
	charmlog.Options // embed Options instead of pointer

	Writer     io.Writer
	Styles     *Styles
	Default    bool
	OutputFunc func() (io.Writer, error)

	// Log rotation settings
	RotationEnabled  bool
	RotationMaxSize  string
	RotationMaxFiles int
}

Options represents logger configuration options

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns the default logger options

func (*Options) Apply

func (o *Options) Apply(opts ...Option) error

Apply applies the given options

type Styles

type Styles = charmlog.Styles

func DefaultStyles

func DefaultStyles() *Styles

DefaultStyles returns the initialized styles with all levels including Important

type TimeFunction

type TimeFunction = func(time.Time) time.Time

Jump to

Keyboard shortcuts

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