log

package
v0.0.195 Latest Latest
Warning

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

Go to latest
Published: May 7, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package log provides a unified way to log messages across LoungeUp applications.

The default Logger is pre-configured and ready to use.

// Log a debug message with the default logger.
log.Default().Debug("Initializing application", slog.String("version", "0.0.1"))

if err := startServer(); err != nil {
	// Log an error message with the default logger.
	log. Default().Error("Could not start server",
		slog.String("error", err.Error()),
		slog.String("version", "0.0.1"),
	)
}

You can automatically send log messages to Datadog. Use the pre-defined methods to add the 'formattedMessage' log attribute.

// Log a debug message with the default logger and automatically add a 'formattedMessage' attribute.
log.Default().FormattedDebug("Initializing application", slog.String("version", "0.0.1"))
log.Default().FormattedError("Could not initialize application", slog.String("version", "0.0.1"))

You can use the Adapter to pass our pre-configured logger to external libraries.

// Use the adapter of the default logger with the 'go-res' library.
res.NewService("example").SetLogger(log.Default().Adapter)

// Use the adapter of the default logger with the 'badger' library.
badger.Open(badger.DefaultOptions("/tmp/").WithLogger(log.Default().Adapter))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandlePanic

func HandlePanic()

Types

type Adapter

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

Adapter for external libraries. It is used to adapt the logger by implementing interfaces required by external libraries. It is not intended to be used directly by the application.

func NewAdapter

func NewAdapter(logger *Logger, options ...AdapterOption) *Adapter

func (*Adapter) Debugf

func (a *Adapter) Debugf(message string, attributes ...any)

func (*Adapter) Errorf

func (a *Adapter) Errorf(message string, attributes ...any)

func (*Adapter) Infof

func (a *Adapter) Infof(message string, attributes ...any)

func (*Adapter) Tracef

func (a *Adapter) Tracef(message string, attributes ...any)

func (*Adapter) Warningf

func (a *Adapter) Warningf(message string, attributes ...any)

type AdapterOption

type AdapterOption func(*Adapter)

func DisableAdapterTraceLogs

func DisableAdapterTraceLogs() AdapterOption

type Logger

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

Logger used by LoungeUp applications based on the official log/slog package.

func Default

func Default() *Logger

Default returns the default logger.

func NewLogger

func NewLogger(options ...LoggerOption) *Logger

NewLogger creates a new Logger with the given options.

func (*Logger) Debug

func (l *Logger) Debug(message string, attributes ...slog.Attr)

Debug logs a debug message with the given attributes.

func (*Logger) Error

func (l *Logger) Error(message string, attributes ...slog.Attr)

Error logs an error message with the given attributes.

func (*Logger) FormattedDebug

func (l *Logger) FormattedDebug(message string, attributes ...slog.Attr)

FormattedDebug logs a debug message with the given attributes and automatically adds a formatted message attribute. The formatted message attribute is used to send logs to Datadog.

func (*Logger) FormattedError

func (l *Logger) FormattedError(message string, attributes ...slog.Attr)

FormattedError logs an error message with the given attributes and automatically adds a formatted message attribute. The formatted message attribute is used to send logs to Datadog.

func (*Logger) With

func (l *Logger) With(attributes ...slog.Attr) *Logger

With works like the With method of the official log/slog package.

func (*Logger) WithGroup

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

WithGroup works like the WithGroup method of the official log/slog package.

type LoggerOption

type LoggerOption func(*Logger)

LoggerOption is a type of function that configures a Logger.

func WithLoggerWriter

func WithLoggerWriter(w io.Writer) LoggerOption

WithLoggerWriter sets the writer of the logger.

Jump to

Keyboard shortcuts

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