log.go 679 B

1234567891011121314151617181920212223
  1. package log
  2. import (
  3. "context"
  4. "log"
  5. "runtime"
  6. )
  7. // Logger is the interface used to log panics that occur during query execution. It is settable via graphql.ParseSchema
  8. type Logger interface {
  9. LogPanic(ctx context.Context, value interface{})
  10. }
  11. // DefaultLogger is the default logger used to log panics that occur during query execution
  12. type DefaultLogger struct{}
  13. // LogPanic is used to log recovered panic values that occur during query execution
  14. func (l *DefaultLogger) LogPanic(_ context.Context, value interface{}) {
  15. const size = 64 << 10
  16. buf := make([]byte, size)
  17. buf = buf[:runtime.Stack(buf, false)]
  18. log.Printf("graphql: panic occurred: %v\n%s", value, buf)
  19. }