File: writer.go

package info (click to toggle)
golang-github-graylog2-go-gelf 0.0%2Bgit20191017.1550ee6-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-proposed-updates, bullseye, forky, sid, trixie
  • size: 144 kB
  • sloc: makefile: 2
file content (34 lines) | stat: -rw-r--r-- 773 bytes parent folder | download | duplicates (2)
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
// 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"
)

type Writer interface {
	Close() error
	Write([]byte) (int, error)
	WriteMessage(*Message) error
}

// 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).
type GelfWriter struct {
	addr     string
	conn     net.Conn
	hostname string
	Facility string // defaults to current process name
	proto    string
}

// Close connection and interrupt blocked Read or Write operations
func (w *GelfWriter) Close() error {
	if w.conn == nil {
		return nil
	}
	return w.conn.Close()
}