func (s *TCPServer) accept(c net.Conn) {
	defer func() {
		s.b.DelSubscriber(s.name)
		log.Printf("[%s - %s] closing tcp connection", s.name, c.RemoteAddr().String())
		c.Close()
	}()
	log.Printf("[%s - %s] accepting tcp connection", s.name, c.RemoteAddr().String())
	r := make(chan *buffer.Event, recvBuffer)
	s.b.AddSubscriber(s.name, r)
	for {
		select {
		case ev := <-r:
			var allowed bool
			allowed = true
			for key, value :=  range s.fields {
				if ((*ev.Fields)[key] == nil || ((*ev.Fields)[key] != nil && value != (*ev.Fields)[key].(string))) {
					allowed = false
					break
				}
                        }
                        if allowed && server.RandInt(0, 100) < *s.config.SampleSize {
				_, err := c.Write([]byte(fmt.Sprintf("%s %s\n", ev.Source, *ev.Text)))
				if err != nil {
					log.Printf("[%s - %s] error sending event to tcp connection: %v", s.name, c.RemoteAddr().String(), err)
					return
				}
			}
		}
	}
}
lumberConn handles an incoming connection from a lumberjack client
package tcp
import (
	"fmt"
	"log"
	"net"
	"github.com/packetzoom/logzoom/buffer"
	"github.com/packetzoom/logzoom/output"
	"github.com/packetzoom/logzoom/route"
	"github.com/packetzoom/logzoom/server"
	"gopkg.in/yaml.v2"
)
const (
	recvBuffer = 100
)
type Config struct {
	Host string `yaml:"host"`
	SampleSize *int `yaml:"sample_size,omitempty"`
}
type TCPServer struct {
	name string
	fields map[string]string
	b    buffer.Sender
	term chan bool
	config *Config
}
func init() {
	output.Register("tcp", New)
}
func New() (output.Output) {
	return &TCPServer{term: make(chan bool, 1)}
}