clogg

package module
v0.2.1-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2025 License: MIT Imports: 6 Imported by: 3

README

Clog

clogg is a simple, fast, and asynchronous logging package for Go, built entirely with the standard library. It wraps the log/slog package to provide non-blocking, structured logging by processing logs in a separate goroutine. Designed for performance and ease of use, clogg offers a clean API and integrates seamlessly into your Go applications.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, msg string, attrs ...Attr)

func Error

func Error(ctx context.Context, msg string, attrs ...Attr)

func Info

func Info(ctx context.Context, msg string, attrs ...Attr)

func Warn

func Warn(ctx context.Context, msg string, attrs ...Attr)

Types

type Attr

type Attr = slog.Attr

Attr is an alias for slog.Attr, used to define structured attributes for log messages.

func Bool

func Bool(key string, value bool) Attr

Bool creates a new Attr with a boolean value.

func Float64

func Float64(key string, value float64) Attr

Float64 creates a new Attr with a float64 value.

func Int

func Int(key string, value int) Attr

Int creates a new Attr with an integer value.

func String

func String(key, value string) Attr

String creates a new Attr with a string value.

func Time

func Time(key string, value time.Time) Attr

Time creates a new Attr with a time.Time value.

type Logger

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

Logger is an asynchronous logger that processes log messages in a separate goroutine. It provides methods to log messages at different severity levels (Debug, Info, Warn, Error).

func GetLogger

func GetLogger(config LoggerConfig) *Logger

GetLogger returns the singleton instance of the Logger. If the logger has not been initialized, it initializes it with the provided configuration.

func (*Logger) Shutdown

func (l *Logger) Shutdown()

Shutdown gracefully shuts down the logger by ensuring that all pending log messages in the logChan channel are processed before the logger stops.

Steps:

  1. It closes the logChan channel to signal the processLogs goroutine that no more log messages will be sent.
  2. It waits for the done channel to be closed, which indicates that the processLogs goroutine has finished processing all remaining log messages and has exited.

This ensures that no log messages are lost during shutdown and that the logger shuts down cleanly.

type LoggerConfig

type LoggerConfig struct {
	BufferSize int
	Handler    slog.Handler
}

LoggerConfig defines the configuration for the Logger.

Fields: - BufferSize: The size of the buffered channel used to enqueue log messages for asynchronous processing. - Handler: The slog.Handler used to format and output log messages.

Jump to

Keyboard shortcuts

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