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 ¶
- func HandlePanic()
- type Adapter
- func (a *Adapter) Debugf(message string, attributes ...any)
- func (a *Adapter) Errorf(message string, attributes ...any)
- func (a *Adapter) Infof(message string, attributes ...any)
- func (a *Adapter) Tracef(message string, attributes ...any)
- func (a *Adapter) Warningf(message string, attributes ...any)
- type AdapterOption
- type Logger
- func (l *Logger) Debug(message string, attributes ...slog.Attr)
- func (l *Logger) Error(message string, attributes ...slog.Attr)
- func (l *Logger) FormattedDebug(message string, attributes ...slog.Attr)
- func (l *Logger) FormattedError(message string, attributes ...slog.Attr)
- func (l *Logger) With(attributes ...slog.Attr) *Logger
- func (l *Logger) WithGroup(name string) *Logger
- type LoggerOption
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
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 NewLogger ¶
func NewLogger(options ...LoggerOption) *Logger
NewLogger creates a new Logger with the given options.
func (*Logger) FormattedDebug ¶
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 ¶
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.
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.