Skip to main content

slog_noop.go

slog_noop.go - Overview

This file defines a no-op implementation of the slog.Handler interface from the log/slog package. It's designed for situations where logging is not required, effectively silencing all log output.

Detailed Documentation

SlogNoopHandler

type SlogNoopHandler struct{}
  • Purpose: Represents a no-op handler for the log/slog package. It implements the slog.Handler interface but performs no actual logging.

Enabled

func (h SlogNoopHandler) Enabled(context.Context, slog.Level) bool { return false }
  • Purpose: Determines if a given log level is enabled.
  • Parameters:
    • context.Context: The context.
    • slog.Level: The log level to check.
  • Returns: bool: Always returns false, indicating that no log level is enabled.

Handle

func (h SlogNoopHandler) Handle(context.Context, slog.Record) error { return nil }
  • Purpose: Handles a log record.
  • Parameters:
    • context.Context: The context.
    • slog.Record: The log record to handle.
  • Returns: error: Always returns nil, indicating successful (but no-op) handling.

WithAttrs

func (h SlogNoopHandler) WithAttrs([]slog.Attr) slog.Handler { return h }
  • Purpose: Creates a new handler with the given attributes.
  • Parameters:
    • []slog.Attr: The attributes to add.
  • Returns: slog.Handler: Returns the original SlogNoopHandler instance.

WithGroup

func (h SlogNoopHandler) WithGroup(string) slog.Handler { return h }
  • Purpose: Creates a new handler with the given group.
  • Parameters:
    • string: The group name.
  • Returns: slog.Handler: Returns the original SlogNoopHandler instance.

Getting Started Relevance