plugins/logger
API reference for the plugins/logger package, generated from Go doc comments.
import "github.com/grx-gql/grx/plugins/logger"Package logger provides a plugins.Plugin that records GraphQL request lifecycle events through a structured slog logger. It is the canonical example of a built-in plugin and a useful drop-in for production observability.
Index
- type Config
- type Logger
- func New(config Config) (*Logger, error)
- func (l *Logger) Error(ctx context.Context, err error)
- func (l *Logger) ExecutionStart(ctx context.Context, req core.Request) error
- func (l *Logger) FieldResolveStart(ctx context.Context, field plugins.FieldContext) error
- func (l *Logger) ParsingStart(ctx context.Context, req core.Request) error
- func (l *Logger) RequestStart(ctx context.Context, req core.Request) (context.Context, error)
- func (l *Logger) ResponseSend(ctx context.Context, res core.Response) error
- func (l *Logger) ValidationStart(ctx context.Context, req core.Request) error
type Config
Config configures a Logger. Logger is required.
type Config struct {
// Logger is the slog logger used to emit lifecycle events. The
// plugin attaches the request context to every log call so that
// per-request fields propagated via the context are preserved.
Logger *slog.Logger
}type Logger
Logger is a plugins.Plugin that emits a structured log entry at every stage of the GraphQL request lifecycle. It embeds plugins.Base and therefore satisfies the full Plugin interface.
type Logger struct {
plugins.Base
// contains filtered or unexported fields
}func New
func New(config Config) (*Logger, error)New constructs a Logger. It returns an error when config.Logger is nil so that misconfigured deployments fail fast at startup.
func (*Logger) Error
func (l *Logger) Error(ctx context.Context, err error)Error logs an error that aborted the request.
func (*Logger) ExecutionStart
func (l *Logger) ExecutionStart(ctx context.Context, req core.Request) errorExecutionStart logs the start of the execution phase.
func (*Logger) FieldResolveStart
func (l *Logger) FieldResolveStart(ctx context.Context, field plugins.FieldContext) errorFieldResolveStart logs that a field resolver is about to be invoked. Field-level events are emitted at debug level to keep production logs manageable on schemas with large selection sets.
func (*Logger) ParsingStart
func (l *Logger) ParsingStart(ctx context.Context, req core.Request) errorParsingStart logs the start of the parsing phase.
func (*Logger) RequestStart
func (l *Logger) RequestStart(ctx context.Context, req core.Request) (context.Context, error)RequestStart logs that a request has begun and returns ctx unchanged.
func (*Logger) ResponseSend
func (l *Logger) ResponseSend(ctx context.Context, res core.Response) errorResponseSend logs that a response is about to be returned to the client.
func (*Logger) ValidationStart
func (l *Logger) ValidationStart(ctx context.Context, req core.Request) errorValidationStart logs the start of the validation phase.
Generated by gomarkdoc
Last updated on