From 550db511ba72a75c4a921cf4b1a94d2075fdaaf1 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Sat, 16 Dec 2017 01:39:42 -0700 Subject: [PATCH] Add event framework --- event/logger.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 event/logger.go diff --git a/event/logger.go b/event/logger.go new file mode 100644 index 00000000..43d58dfa --- /dev/null +++ b/event/logger.go @@ -0,0 +1,39 @@ +package event + +import ( + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/tools/record" +) + +type Logger interface { + Info(obj runtime.Object, message string) + Infof(obj runtime.Object, messagefmt string, args ...interface{}) + Error(obj runtime.Object, message string) + Errorf(obj runtime.Object, messagefmt string, args ...interface{}) +} + +type logger struct { + recorder record.EventRecorder +} + +func (l *logger) Info(obj runtime.Object, message string) { + l.recorder.Event(obj, "Normal", "Message", message) +} + +func (l *logger) Infof(obj runtime.Object, messagefmt string, args ...interface{}) { + l.recorder.Eventf(obj, "Normal", "Message", messagefmt, args...) +} + +func (l *logger) Error(obj runtime.Object, message string) { + l.recorder.Event(obj, "Warning", "Message", message) +} + +func (l *logger) Errorf(obj runtime.Object, messagefmt string, args ...interface{}) { + l.recorder.Eventf(obj, "Warning", "Message", messagefmt, args...) +} + +func NewLogger(recorder record.EventRecorder) Logger { + return &logger{ + recorder: recorder, + } +}