logger

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvProd = "prod"
	EnvDev  = "dev"
)

Environment constants

View Source
const (
	LevelDebug = slog.LevelDebug
	LevelInfo  = slog.LevelInfo
	LevelWarn  = slog.LevelWarn
	LevelError = slog.LevelError
)

Log levels

Variables

This section is empty.

Functions

func PrettyLogHandler

func PrettyLogHandler(env string, level slog.Level) *slog.Logger

PrettyLogHandler creates a pretty logger for development environments

Types

type AppLogger

type AppLogger struct {
	*slog.Logger
	// contains filtered or unexported fields
}

AppLogger wraps slog.Logger with additional functionality

func GetLoggerInstance

func GetLoggerInstance() *AppLogger

GetLoggerInstance returns the logger singleton instance Panics if the logger has not been initialized

func InitLogger

func InitLogger(env string, levelOrDebug interface{}, loggerOptions env.Logger) *AppLogger

InitLogger initializes the logger singleton with the specified environment and log level If level is not specified (0), it will default to Info for prod and Debug for dev

func (*AppLogger) Close

func (l *AppLogger) Close() error

Close closes the logger's file writer if any

func (*AppLogger) DebugContext

func (l *AppLogger) DebugContext(ctx context.Context, msg string, keyvals ...any)

DebugContext logs a debug message with context and structured data

func (*AppLogger) Debugf

func (l *AppLogger) Debugf(msg string, args ...interface{})

Debugf logs a debug message

func (*AppLogger) EnableFileLogging

func (l *AppLogger) EnableFileLogging(filePath string) error

EnableFileLogging enables logging to a file in addition to the console

func (*AppLogger) Error

func (l *AppLogger) Error(msg string, err error, keyvals ...any)

Error logs an error message with structured data

func (*AppLogger) ErrorContext

func (l *AppLogger) ErrorContext(ctx context.Context, msg string, err error, keyvals ...any)

ErrorContext logs an error message with context and structured data

func (*AppLogger) ErrorWithStack

func (l *AppLogger) ErrorWithStack(msg string, err error)

ErrorWithStack logs an error with its stack trace if available

func (*AppLogger) Errorf

func (l *AppLogger) Errorf(msg string, args ...interface{})

Errorf logs an error message

func (*AppLogger) Fatalf

func (l *AppLogger) Fatalf(msg string, args ...interface{})

Fatalf logs a fatal error message and exits the program

func (*AppLogger) InfoContext

func (l *AppLogger) InfoContext(ctx context.Context, msg string, keyvals ...any)

InfoContext logs an info message with context and structured data

func (*AppLogger) Infof

func (l *AppLogger) Infof(msg string, args ...interface{})

Infof logs an info message

func (*AppLogger) WarnContext

func (l *AppLogger) WarnContext(ctx context.Context, msg string, keyvals ...any)

WarnContext logs a warning message with context and structured data

func (*AppLogger) Warnf

func (l *AppLogger) Warnf(msg string, args ...interface{})

Warnf logs a warning message

func (*AppLogger) With

func (l *AppLogger) With(args ...any) *AppLogger

With returns a logger with the given attributes

func (*AppLogger) WithContext

func (l *AppLogger) WithContext(ctx context.Context) *slog.Logger

WithContext returns a logger with context values

func (*AppLogger) WithGroup

func (l *AppLogger) WithGroup(name string) *AppLogger

WithGroup returns a logger with the given group

Jump to

Keyboard shortcuts

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