net_conn.go 774 B

12345678910111213141516171819202122232425262728293031
  1. package srslog
  2. import (
  3. "net"
  4. )
  5. // netConn has an internal net.Conn and adheres to the serverConn interface,
  6. // allowing us to send syslog messages over the network.
  7. type netConn struct {
  8. conn net.Conn
  9. }
  10. // writeString formats syslog messages using time.RFC3339 and includes the
  11. // hostname, and sends the message to the connection.
  12. func (n *netConn) writeString(framer Framer, formatter Formatter, p Priority, hostname, tag, msg string) error {
  13. if framer == nil {
  14. framer = DefaultFramer
  15. }
  16. if formatter == nil {
  17. formatter = DefaultFormatter
  18. }
  19. formattedMessage := framer(formatter(p, hostname, tag, msg))
  20. _, err := n.conn.Write([]byte(formattedMessage))
  21. return err
  22. }
  23. // close the network connection
  24. func (n *netConn) close() error {
  25. return n.conn.Close()
  26. }