writer.go 773 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2012 SocialCode. All rights reserved.
  2. // Use of this source code is governed by the MIT
  3. // license that can be found in the LICENSE file.
  4. package gelf
  5. import (
  6. "net"
  7. )
  8. type Writer interface {
  9. Close() error
  10. Write([]byte) (int, error)
  11. WriteMessage(*Message) error
  12. }
  13. // Writer implements io.Writer and is used to send both discrete
  14. // messages to a graylog2 server, or data from a stream-oriented
  15. // interface (like the functions in log).
  16. type GelfWriter struct {
  17. addr string
  18. conn net.Conn
  19. hostname string
  20. Facility string // defaults to current process name
  21. proto string
  22. }
  23. // Close connection and interrupt blocked Read or Write operations
  24. func (w *GelfWriter) Close() error {
  25. if w.conn == nil {
  26. return nil
  27. }
  28. return w.conn.Close()
  29. }