diff --git a/eventhandler.go b/eventhandler.go new file mode 100644 index 0000000..e1eaad5 --- /dev/null +++ b/eventhandler.go @@ -0,0 +1,36 @@ +package profiler + +import ( + "log/slog" + "os" +) + +// EventType represents the event type +type EventType int + +// Event types +const ( + DebugEvent = iota + InfoEvent + ErrorEvent +) + +// EventHandler function to handle log events +type EventHandler func(t EventType, v string, args ...any) + +func DefaultEventHandler() EventHandler { + l := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ + Level: slog.LevelDebug, + })) + + return func(eventType EventType, msg string, args ...any) { + switch eventType { + case DebugEvent: + l.Debug(msg, args...) + case ErrorEvent: + l.Error(msg, args...) + default: + l.Info(msg, args...) + } + } +}