log

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Stdout destinationType = "stdout"
	File   destinationType = "file"
)

Destination types for logging output.

View Source
const (
	DebugLevel level = "debug"
	InfoLevel  level = "info"
	WarnLevel  level = "warn"
	ErrorLevel level = "error"
	FatalLevel level = "fatal"
	PanicLevel level = "panic"
)

Log levels define the severity of log messages.

Variables

View Source
var (
	ErrInvalidLogLevel   = errors.New("invalid log level")
	ErrLogDestinationNil = errors.New("log Destinations cant be empty")
	ErrMissingFilePath   = errors.New("file path missing in destination config for file logging")
)

Logger instance and configuration.

Functions

func Debug

func Debug(ctx context.Context, msg string)

Debug logs a debug-level message with the provided context.

func Debugf

func Debugf(ctx context.Context, format string, v ...any)

Debugf logs a formatted debug-level message with the provided context.

func Error

func Error(ctx context.Context, err error, msg string)

Error logs an error-level message along with an error object.

func Errorf

func Errorf(ctx context.Context, err error, format string, v ...any)

Errorf logs a formatted error-level message along with an error object.

func Fatal

func Fatal(ctx context.Context, err error, msg string)

Fatal logs a fatal-level message along with an error object and exits the application.

func Fatalf

func Fatalf(ctx context.Context, err error, format string, v ...any)

Fatalf logs a formatted fatal-level message along with an error object and exits the application.

func Info

func Info(ctx context.Context, msg string)

Info logs an info-level message with the provided context.

func Infof

func Infof(ctx context.Context, format string, v ...any)

Infof logs a formatted info-level message with the provided context.

func InitLogger

func InitLogger(c Config) error

InitLogger initializes the logger with the given configuration. It ensures that the logger is initialized only once using sync.Once.

func Panic

func Panic(ctx context.Context, err error, msg string)

Panic logs a panic-level message along with an error object and panics.

func Panicf

func Panicf(ctx context.Context, err error, format string, v ...any)

Panicf logs a formatted panic-level message along with an error object and panics.

func Request

func Request(ctx context.Context, r *http.Request, body []byte)

Request logs details of an incoming HTTP request, including method, URL, body, and remote address.

func Response

func Response(ctx context.Context, r *http.Request, statusCode int, responseTime time.Duration)

Response logs details of an outgoing HTTP response, including method, URL, status code, and response time.

func Warn

func Warn(ctx context.Context, msg string)

Warn logs a warning-level message with the provided context.

func Warnf

func Warnf(ctx context.Context, format string, v ...any)

Warnf logs a formatted warning-level message with the provided context.

Types

type Config

type Config struct {
	Level        level              `yaml:"level"`
	Destinations []destination      `yaml:"destinations"`
	ContextKeys  []model.ContextKey `yaml:"contextKeys"`
}

Config represents the configuration for logging.

Jump to

Keyboard shortcuts

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