log

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: BSD-2-Clause Imports: 3 Imported by: 12

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 interface{})

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

type Logger

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

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 interface{})

LoggerFunc is a function type that implements the Logger interface.

Example
logfn := log.LoggerFunc(func(ctx context.Context, err interface{}) {
	// 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 interface{})

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