Documentation
¶
Overview ¶
Package gelf provides a Gelf Handler for log15 in order to enable logging to Graylog taken from https://gist.github.com/jmtuley/d4b09617967e59c58c3e and parts from https://github.com/gemnasium/logrus-hooks it has no external dependencies outside the std library and of course log15 the actual Handler still resides inside the log15 package; here we have the supporting functions
Index ¶
Constants ¶
const (
ChunkSize = 1420
)
Used to control GELF chunking. Should be less than (MTU - len(UDP header)).
TODO: generate dynamically using Path MTU Discovery?
Variables ¶
var Must muster
Must encapsulates GelfHandler and panics if it returns an error.
Functions ¶
func Handler ¶
Handler returns a handler that writes GELF messages to a service at gelfAddr. It is already wrapped in log15's CallerFileHandler and SyncHandler helpers. Its error is non-nil if there is a problem creating the GELF writer or determining our hostname. address is in the format host:port.
h,err:=gelf.GelfHandler("myhost:12201")
Types ¶
type CompressType ¶
type CompressType int
CompressType tells what compression type the writer should use when sending messages to the graylog2 server
const ( // CompressGzip indicates gzip compression CompressGzip CompressType = iota // CompressZlib indicates zlib compression CompressZlib )
type Message ¶
type Message struct { Version string `json:"version"` Host string `json:"host"` Short string `json:"short_message"` Full string `json:"full_message"` TimeUnix float64 `json:"timestamp"` Level int32 `json:"level"` Facility string `json:"facility"` File string `json:"file"` Line int `json:"line"` Extra map[string]interface{} `json:"-"` }
Message represents the contents of the GELF message. It is gzipped before sending.
func (*Message) MarshalJSON ¶
MarshalJSON marshals a message to json
func (*Message) UnmarshalJSON ¶
UnmarshalJSON unmarshals a message from json
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader provides interanl structures for a Reader
func NewReader ¶
NewReader returns a reader listening to udp traffic at an address in the form "host:port". if port is 0, a new free address is taken. Retrieve it with Addr(). The reader is mainly intended for testing
func (*Reader) Read ¶
Read reads date into a fixed size buffer. ATTN: this will discard data if p isn't big enough to hold the full message.
func (*Reader) ReadMessage ¶
ReadMessage reads a Message
type Writer ¶
type Writer struct { Facility string // defaults to current process name CompressionLevel int // one of the consts from compress/flate CompressionType CompressType // contains filtered or unexported fields }
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).
func NewWriter ¶
NewWriter returns a new GELF Writer. This writer can be used to send the output of the standard Go log functions to a central GELF server by passing it to log.SetOutput()
func (*Writer) WriteMessage ¶
WriteMessage sends the specified message to the GELF server specified in the call to New(). It assumes all the fields are filled out appropriately. In general, clients will want to use Write, rather than WriteMessage.