2015-05-29 17:00:46 -04:00
|
|
|
// Copyright 2012 SocialCode. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package gelf
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
2017-09-05 13:42:18 -04:00
|
|
|
type Writer interface {
|
|
|
|
Close() error
|
|
|
|
Write([]byte) (int, error)
|
|
|
|
WriteMessage(*Message) error
|
|
|
|
}
|
|
|
|
|
2015-05-29 17:00:46 -04:00
|
|
|
// Writer implements io.Writer and is used to send both discrete
|
|
|
|
// messages to a graylog2 server, or data from a stream-oriented
|
|
|
|
// interface (like the functions in log).
|
2017-09-05 13:42:18 -04:00
|
|
|
type GelfWriter struct {
|
|
|
|
addr string
|
|
|
|
conn net.Conn
|
|
|
|
hostname string
|
|
|
|
Facility string // defaults to current process name
|
|
|
|
proto string
|
2015-05-29 17:00:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Close connection and interrupt blocked Read or Write operations
|
2017-09-05 13:42:18 -04:00
|
|
|
func (w *GelfWriter) Close() error {
|
2017-12-11 09:22:51 -05:00
|
|
|
if w.conn == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2016-01-21 07:28:25 -05:00
|
|
|
return w.conn.Close()
|
2015-05-29 17:00:46 -04:00
|
|
|
}
|