You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: tcp.go
    path of file: ./repos/cds/sdk/log/hook
    
    the code of the file until where you have to start completion: // Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
// inspired from github.com/gemnasium/logrus-graylog-hook

package hook

import (
	"bytes"
	"crypto/tls"
	"encoding/json"
	"fmt"
	"net"
	"os"
	"path"
	"sync"
	"time"

	"github.com/eapache/go-resiliency/retrier"
)

// TCPWriter implements io.Writer and is 
    
func NewTCPWriter(addr string, tlsCfg *tls.Config) (*TCPWriter, error) {
	w := new(TCPWriter)

	const dialTimeout = 5 * time.Second

	// If TLS configuration is specified, try to connect with it
	if tlsCfg != nil {
		w.connect = func() (net.Conn, error) {
			return tls.DialWithDialer(&net.Dialer{Timeout: dialTimeout}, "tcp", addr, tlsCfg)
		}
	} else {
		w.connect = func() (net.Conn, error) { return net.DialTimeout("tcp", addr, dialTimeout) }
	}

	// Get Hostname if possible, otherwise just set to localhost
	var err error
	if w.Hostname, err = os.Hostname(); err != nil {
		w.Hostname = "localhost"
	}

	// Set facility to binary name
	w.Facility = path.Base(os.Args[0])

	return w, nil
}