forked from mcuadros/go-syslog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
35 lines (27 loc) · 820 Bytes
/
handler.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
package syslog
import (
"gopkg.in/mcuadros/go-syslog.v2/format"
)
//The handler receive every syslog entry at Handle method
type Handler interface {
Handle(format.LogParts, int64, error)
}
type LogPartsChannel chan format.LogParts
//The ChannelHandler will send all the syslog entries into the given channel
type ChannelHandler struct {
channel LogPartsChannel
}
//NewChannelHandler returns a new ChannelHandler
func NewChannelHandler(channel LogPartsChannel) *ChannelHandler {
handler := new(ChannelHandler)
handler.SetChannel(channel)
return handler
}
//The channel to be used
func (h *ChannelHandler) SetChannel(channel LogPartsChannel) {
h.channel = channel
}
//Syslog entry receiver
func (h *ChannelHandler) Handle(logParts format.LogParts, messageLength int64, err error) {
h.channel <- logParts
}