-
Notifications
You must be signed in to change notification settings - Fork 6
/
recorder.go
60 lines (47 loc) · 1.46 KB
/
recorder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package slack
import (
"fmt"
"github.com/openshift/library-go/pkg/operator/events"
"k8s.io/klog"
)
type Recorder struct {
client ChannelClient
component string
}
var _ events.Recorder = &Recorder{}
func NewRecorder(client ChannelClient, component string) events.Recorder {
return &Recorder{
client: client,
component: component,
}
}
func (r *Recorder) Event(reason, message string) {
msg := fmt.Sprintf("[*%s#%s*] %s", r.component, reason, message)
if err := r.client.MessageChannel(msg); err != nil {
klog.Warningf("Failed to send: %s (%v)", msg, err)
}
}
func (r *Recorder) Eventf(reason, messageFmt string, args ...interface{}) {
r.Event(reason, fmt.Sprintf(messageFmt, args...))
}
func (r *Recorder) Warning(reason, message string) {
msg := fmt.Sprintf(":warning: [*%s#%s*] %s", r.component, reason, message)
if err := r.client.MessageChannel(msg); err != nil {
klog.Warningf("Failed to send: %s (%v)", msg, err)
}
}
func (r *Recorder) Warningf(reason, messageFmt string, args ...interface{}) {
r.Warning(reason, fmt.Sprintf(messageFmt, args...))
}
func (r *Recorder) ForComponent(componentName string) events.Recorder {
newRecorder := *r
newRecorder.component = componentName
return &newRecorder
}
func (r *Recorder) WithComponentSuffix(componentNameSuffix string) events.Recorder {
return r.ForComponent(r.component + "_" + componentNameSuffix)
}
func (r *Recorder) ComponentName() string {
return r.component
}
func (r *Recorder) Shutdown() {}