func Dial(clientHostname, network, raddr string, rootCAs *x509.CertPool, connectTimeout time.Duration, writeTimeout time.Duration, tcpMaxLineLength int) (*Logger, error) {
	conn, err := dial(network, raddr, rootCAs, connectTimeout)
	logger := &Logger{
		ClientHostname:   clientHostname,
		network:          network,
		raddr:            raddr,
		rootCAs:          rootCAs,
		Packets:          make(chan Packet, 100),
		Errors:           make(chan error, 0),
		connectTimeout:   connectTimeout,
		writeTimeout:     writeTimeout,
		conn:             conn,
		tcpMaxLineLength: tcpMaxLineLength,
		stopChan:         make(chan struct{}, 1),
	}
	go logger.writeLoop()
	return logger, err
}
Dial connects to the syslog server at raddr, using the optional certBundle,
and launches a goroutine to watch logger.Packets for messages to log.
package syslog
import (
	_ "crypto/sha512"
	"crypto/tls"
	"crypto/x509"
	"fmt"
	"io"
	"net"
	"sync"
	"time"
)
type conn struct {
	netConn net.Conn
	errors  chan error
}
func (c *conn) watch() {
	for {
		data := make([]byte, 1)
		_, err := c.netConn.Read(data)
		if err != nil {
			c.netConn.Close()
			c.errors <- err
			return
		}
	}
}
func (c *conn) reconnectNeeded() bool {
	if c == nil {
		return true
	}
	select {
	case <-c.errors:
		return true
	default:
		return false
	}
}
func (c *conn) Close() error {
	return c.netConn.Close()
}
func dial(network, raddr string, rootCAs *x509.CertPool, connectTimeout time.Duration) (*conn, error) {
	var netConn net.Conn
	var err error
	switch network {
	case "tls":
		var config *tls.Config
		if rootCAs != nil {
			config = &tls.Config{RootCAs: rootCAs}
		}
		dialer := &net.Dialer{
			Timeout:   connectTimeout,
			KeepAlive: time.Second * 60 * 3,  
		}
		netConn, err = tls.DialWithDialer(dialer, "tcp", raddr, config)
	case "udp", "tcp":
		netConn, err = net.DialTimeout(network, raddr, connectTimeout)
	default:
		return nil, fmt.Errorf("Network protocol %s not supported", network)
	}
	if err != nil {
		return nil, err
	} else {
		c := &conn{netConn, make(chan error)}
		go c.watch()
		return c, nil
	}
}
type Logger struct {
	conn           *conn
	Packets        chan Packet
	Errors         chan error
	ClientHostname string
	network          string
	raddr            string
	rootCAs          *x509.CertPool
	connectTimeout   time.Duration
	writeTimeout     time.Duration
	tcpMaxLineLength int
	mu               sync.RWMutex
	stopChan         chan struct{}
	stopped          bool
}