log

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: BSD-2-Clause Imports: 3 Imported by: 14 modules, 13 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultLogger

type DefaultLogger struct{}

DefaultLogger is the default logger used to log panics that occur during query execution.

func (*DefaultLogger) LogPanic

func (l *DefaultLogger) LogPanic(ctx context.Context, value any)

LogPanic is used to log recovered panic values that occur during query execution.

type Logger

type Logger interface {
	LogPanic(ctx context.Context, value any)
}

Logger is the interface used to log panics that occur during query execution. It is settable via graphql.ParseSchema.

type LoggerFunc added in v1.7.0

type LoggerFunc func(ctx context.Context, value any)

LoggerFunc is a function type that implements the Logger interface.

Example
package main

import (
	"context"
	"fmt"

	"github.com/graph-gophers/graphql-go"
	"github.com/graph-gophers/graphql-go/log"
)

func main() {
	logfn := log.LoggerFunc(func(ctx context.Context, err any) {
		// Here you can handle the panic, e.g., log it or send it to an error tracking service.
		fmt.Printf("graphql: panic occurred: %v", err)
	})

	opts := []graphql.SchemaOpt{
		graphql.Logger(logfn),
		graphql.UseFieldResolvers(),
	}

	schemadef := `
		type Query {
			hello: String!
		}
	`
	resolver := &struct {
		Hello func() string
	}{
		Hello: func() string {
			// Simulate a panic
			panic("something went wrong")
		},
	}

	schema := graphql.MustParseSchema(schemadef, resolver, opts...)
	// Now, when you execute a query that causes a panic, it will be logged using the provided LoggerFunc.
	schema.Exec(context.Background(), "{ hello }", "", nil)

}
Output:
graphql: panic occurred: something went wrong

func (LoggerFunc) LogPanic added in v1.7.0

func (f LoggerFunc) LogPanic(ctx context.Context, value any)

LogPanic calls the LoggerFunc with the given context and panic value.

Jump to

Keyboard shortcuts

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