2016-01-08 12:35:35 -05:00
|
|
|
package srslog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
2016-02-03 15:40:19 -05:00
|
|
|
// netConn has an internal net.Conn and adheres to the serverConn interface,
|
|
|
|
// allowing us to send syslog messages over the network.
|
2016-01-08 12:35:35 -05:00
|
|
|
type netConn struct {
|
|
|
|
conn net.Conn
|
|
|
|
}
|
|
|
|
|
2016-02-03 15:40:19 -05:00
|
|
|
// writeString formats syslog messages using time.RFC3339 and includes the
|
|
|
|
// hostname, and sends the message to the connection.
|
|
|
|
func (n *netConn) writeString(framer Framer, formatter Formatter, p Priority, hostname, tag, msg string) error {
|
|
|
|
if framer == nil {
|
|
|
|
framer = DefaultFramer
|
|
|
|
}
|
|
|
|
if formatter == nil {
|
|
|
|
formatter = DefaultFormatter
|
|
|
|
}
|
|
|
|
formattedMessage := framer(formatter(p, hostname, tag, msg))
|
|
|
|
_, err := n.conn.Write([]byte(formattedMessage))
|
2016-01-08 12:35:35 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-02-03 15:40:19 -05:00
|
|
|
// close the network connection
|
2016-01-08 12:35:35 -05:00
|
|
|
func (n *netConn) close() error {
|
|
|
|
return n.conn.Close()
|
|
|
|
}
|