Skip to content

Commit b3a1165

Browse files
dahankzterbshuster
authored andcommitted
Add NewHookWithConn functions to initialize new hooks using net.conn
To make the Logstash hook more flexible, the following functions are presented: * NewHookWithConn which is similar to NewHook except it receives net.conn * NewHookWithFieldsAndConn which is similar to NewHookWithFields except it receives net.conn Any socket that implements the net.conn interface (such as the goautosocket (gas) package) can be passed.
1 parent c5a17a5 commit b3a1165

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

logstash.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,24 @@ func NewHook(protocol, address, appName string) (*Hook, error) {
1919
return NewHookWithFields(protocol, address, appName, make(logrus.Fields))
2020
}
2121

22+
// NewHookWithConn creates a new hook to a Logstash instance, using the supplied connection
23+
func NewHookWithConn(conn net.Conn, appName string) (*Hook, error) {
24+
return NewHookWithFieldsAndConn(conn, appName, make(logrus.Fields))
25+
}
26+
2227
// NewHookWithFields creates a new hook to a Logstash instance, which listens on
2328
// `protocol`://`address`. alwaysSentFields will be sent with every log entry.
2429
func NewHookWithFields(protocol, address, appName string, alwaysSentFields logrus.Fields) (*Hook, error) {
2530
conn, err := net.Dial(protocol, address)
2631
if err != nil {
2732
return nil, err
2833
}
34+
return NewHookWithFieldsAndConn(conn, appName, alwaysSentFields)
35+
}
36+
37+
// NewHookWithFieldsAndConn creates a new hook to a Logstash instance using the supplied connection
38+
//The new Hook
39+
func NewHookWithFieldsAndConn(conn net.Conn, appName string, alwaysSentFields logrus.Fields) (*Hook, error) {
2940
return &Hook{conn: conn, appName: appName, alwaysSentFields: alwaysSentFields}, nil
3041
}
3142

0 commit comments

Comments
 (0)