net.go 803 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2016 The G3N Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package logger
  5. import (
  6. "net"
  7. )
  8. // Net is a network writer used for logging.
  9. type Net struct {
  10. conn net.Conn
  11. }
  12. // NewNet creates and returns a pointer to a new Net object along with any error that occurred.
  13. func NewNet(network string, address string) (*Net, error) {
  14. n := new(Net)
  15. conn, err := net.Dial(network, address)
  16. if err != nil {
  17. return nil, err
  18. }
  19. n.conn = conn
  20. return n, nil
  21. }
  22. // Write writes the provided logger event to the network.
  23. func (n *Net) Write(event *Event) {
  24. n.conn.Write([]byte(event.fmsg))
  25. }
  26. // Clone closes the network connection.
  27. func (n *Net) Close() {
  28. n.conn.Close()
  29. }
  30. func (n *Net) Sync() {
  31. }