reflect

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 10 Imported by: 2

Documentation

Overview

Package reflect provides a logging layer for exchangers and client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetEnabled

func GetEnabled(ctx context.Context, name string) (slog.LogLevel, bool)

GetEnabled tests if the context enables the specified reflection layer or not.

func GetID

func GetID(ctx context.Context) (string, bool)

GetID extracts the tracing ID from the request's context.

func WithEnabled

func WithEnabled(ctx context.Context, level slog.LogLevel, enabled bool) context.Context

WithEnabled attaches an unconditional reflection layer state regardless the name

func WithEnabledFunc

func WithEnabledFunc(ctx context.Context, cond EnabledFunc) context.Context

WithEnabledFunc attaches a function to determine of a reflection layer is enabled or not.

func WithFormattedID

func WithFormattedID(ctx context.Context, id string) context.Context

WithFormattedID attaches a tracing ID to the request's context.

func WithID

func WithID(ctx context.Context, machID uint16, msgID uint16) context.Context

WithID attaches a tracing ID to the request's context.

Types

type Client

type Client struct {
	Extra  map[string]any
	Rename map[string]string
	// contains filtered or unexported fields
}

Client is a logging wrapper for another client.Client. Client will log requests and responses if `GetEnabled(ctx)` returns true.

func NewWithClient

func NewWithClient(name string, log slog.Logger, next client.Client) (*Client, error)

NewWithClient creates a new Client wrapper to log requests and responses to the specified client.Client.

func (*Client) ExchangeContext

func (c *Client) ExchangeContext(ctx context.Context, req *dns.Msg,
	server string) (*dns.Msg, time.Duration, error)

ExchangeContext implements the client.Client interface.

func (*Client) Unwrap

func (c *Client) Unwrap() *dns.Client

type EnabledFunc added in v0.7.16

type EnabledFunc func(context.Context, string) (slog.LogLevel, bool)

EnabledFunc represents the signature of the in-context function used to determine if a request should be logged and at what level

type Lookuper

type Lookuper struct {
	Extra  map[string]any
	Rename map[string]string
	// contains filtered or unexported fields
}

Lookuper is a logging wrapper for another resolver.Lookuper or resolver.Exchanger Lookuper will log requests and responses if `GetEnabled(ctx)` returns true.

func NewWithExchanger

func NewWithExchanger(name string, log slog.Logger, next resolver.Exchanger) (*Lookuper, error)

NewWithExchanger creates a new Lookuper wrapper to log requests and responses to the specified resolver.Exchanger.

func NewWithLookuper

func NewWithLookuper(name string, log slog.Logger, next resolver.Lookuper) (*Lookuper, error)

NewWithLookuper creates a new Lookuper wrapper to log requests and responses to the specified resolver.Lookuper. If the next resolver.Lookuper also implements resolver.Exchanger, that interface will be used instead.

func (*Lookuper) Exchange

func (l *Lookuper) Exchange(ctx context.Context, req *dns.Msg) (*dns.Msg, error)

Exchange implements the resolver.Exchanger interface.

func (*Lookuper) Lookup

func (l *Lookuper) Lookup(ctx context.Context, qName string, qType uint16) (*dns.Msg, error)

Lookup implements the resolver.Lookuper interface.

Jump to

Keyboard shortcuts

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