log

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: MIT Imports: 15 Imported by: 11

Documentation

Index

Constants

View Source
const (
	LevelTrace    = slog.Level(-8)
	LevelDebug    = slog.LevelDebug
	LevelInfo     = slog.LevelInfo
	LevelWarn     = slog.LevelWarn
	LevelError    = slog.LevelError
	LevelCritical = slog.Level(12)
	LevelFatal    = slog.Level(14)
)

Level is a wrapper around slog.Leveler. It adds some extra Levels, like Critical.

Variables

View Source
var (
	String = slog.String
	Int    = slog.Int
	Float  = slog.Float64
	Bool   = slog.Bool
	Any    = slog.Any
)

Attrs are wrappers around slog.Attr.

Functions

func NewHandler added in v1.2.0

func NewHandler(pkg string) slog.Handler

NewHandler creates a new slog.Handler with OpenTelemetry support.

Types

type Logger

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

Logger is a wrapper around slog.Logger that adds OpenTelemetry features.

func NewLogger

func NewLogger(pkg string) *Logger

NewLogger creates a new Logger.

func (*Logger) Critical

func (l *Logger) Critical(ctx context.Context, err error, attrs ...slog.Attr)

Critical indicates critical errors that may lead to system failure or data loss. This level is used for situations that are extremely serious and require immediate attention. It does not lead to a crash, but it should be logged and monitored closely.

func (*Logger) Criticalw

func (l *Logger) Criticalw(ctx context.Context, msg string, attrs ...slog.Attr)

Criticalw is semantically equivalent to [Critical], but it logs an error message instead of an error object.

func (*Logger) Debug

func (l *Logger) Debug(ctx context.Context, msg string, attrs ...slog.Attr)

Debug provides information that is useful for debugging but less detailed than trace. It's used for diagnostic information that might be helpful when trying to understand the flow of an application or troubleshoot issues.

func (*Logger) Error

func (l *Logger) Error(ctx context.Context, err error, attrs ...slog.Attr)

Error indicates significant issues that prevent the application from functioning properly.

func (*Logger) Errorw

func (l *Logger) Errorw(ctx context.Context, msg string, attrs ...slog.Attr)

Errorw is semantically equivalent to [Error], but it logs an error message instead of an error object.

func (*Logger) Fatal

func (l *Logger) Fatal(ctx context.Context, err error, attrs ...slog.Attr)

Fatal indicates a fatal error that causes the current goroutine to terminate. This level is used for situations that are extremely serious and require immediate attention.

DANGER: This function uses `runtime.Goexit()`. Therefore, if called within the main goroutine you MUST call `defer os.Exit(0)` at the top of the main function.

func (*Logger) Fatalw

func (l *Logger) Fatalw(ctx context.Context, msg string, attrs ...slog.Attr)

Fatalw is semantically equivalent to [Fatal], but it logs an error message instead of an error object.

DANGER: This function uses `runtime.Goexit()`. Therefore, if called within the main goroutine you MUST call `defer os.Exit(0)` at the top of the main function.

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, msg string, attrs ...slog.Attr)

Info gives general information about the application’s state or normal operations, typically showing what's happening at a higher level.

func (*Logger) Trace added in v1.3.0

func (l *Logger) Trace(ctx context.Context, msg string, attrs ...slog.Attr)

Trace should be used for very detailed, low-level information, usually about the internal state of the application or detailed execution paths. This level is often used for tracing the flow of the application, and it's usually the most verbose.

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, msg string, attrs ...slog.Attr)

Warn indicates potentially harmful situations, but not necessarily errors. Used for things like deprecated features or unusual but non-critical conditions.

Jump to

Keyboard shortcuts

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