Files
go-receipt-tracker/hooks/debug/debug.go
2025-02-03 17:50:47 -05:00

68 lines
1.5 KiB
Go

package debug
import (
"log/slog"
app "git.savin.nyc/alex/go-receipt-tracker/app"
)
// Options contains configuration settings for the debug output.
type Options struct {
// ShowPacketData bool // include decoded packet data (default false)
// ShowPings bool // show ping requests and responses (default false)
// ShowPasswords bool // show connecting user passwords (default false)
}
// Hook is a debugging hook which logs additional low-level information from the server.
type Hook struct {
app.HookBase
Log *slog.Logger
}
// ID returns the ID of the hook.
func (h *Hook) ID() string {
return "debug"
}
// Provides indicates that this hook provides all methods.
func (h *Hook) Provides(b byte) bool {
return true
}
// Init is called when the hook is initialized.
func (h *Hook) Init(config any) error {
if _, ok := config.(*Options); !ok && config != nil {
return app.ErrInvalidConfigType
}
if config == nil {
config = new(Options)
}
// h.config = config.(*Options)
return nil
}
// SetOpts is called when the hook receives inheritable server parameters.
func (h *Hook) SetOpts(l *slog.Logger) {
h.Log = l
h.Log.Debug("", "method", "SetOpts")
}
// Stop is called when the hook is stopped.
func (h *Hook) Stop() error {
h.Log.Debug("", "method", "Stop")
return nil
}
// OnStarted is called when the server starts.
func (h *Hook) OnStarted() {
h.Log.Debug("", "method", "OnStarted")
}
// OnStopped is called when the server stops.
func (h *Hook) OnStopped() {
h.Log.Debug("", "method", "OnStopped")
}