func NewClient(logger *gosteno.Logger, url string) (loggregatorclient.Client, error) { if index := strings.Index(url, "://"); index > 0 { switch url[:index] { case "udp": return loggregatorclient.NewUDPClient(logger, url[index+3:], loggregatorclient.DefaultBufferSize) case "tls": return loggregatorclient.NewTLSClient(logger, url[index+3:]) } } return nil, fmt.Errorf("Unknown scheme for %s", url) }
func NewEmitter(loggregatorServer, sourceName, sourceId, sharedSecret string, logger *gosteno.Logger) (*LoggregatorEmitter, error) { if logger == nil { logger = gosteno.NewLogger("loggregatorlib.emitter") } client, err := loggregatorclient.NewUDPClient(logger, loggregatorServer, loggregatorclient.DefaultBufferSize) if err != nil { return nil, err } e := &LoggregatorEmitter{ sharedSecret: sharedSecret, sn: sourceName, sId: sourceId, LoggregatorClient: client, logger: logger, } e.logger.Debugf("Created new loggregator emitter: %#v", e) return e, nil }
"github.com/onsi/ginkgo/config" . "github.com/onsi/gomega" ) var _ = Describe("Udp Client", func() { var ( client loggregatorclient.Client udpListener *net.UDPConn loggregatorAddress string ) BeforeEach(func() { port := 9875 + config.GinkgoConfig.ParallelNode loggregatorAddress = net.JoinHostPort("127.0.0.1", strconv.Itoa(port)) var err error client, err = loggregatorclient.NewUDPClient(gosteno.NewLogger("TestLogger"), loggregatorAddress, 0) Expect(err).NotTo(HaveOccurred()) udpAddr, _ := net.ResolveUDPAddr("udp", loggregatorAddress) udpListener, _ = net.ListenUDP("udp", udpAddr) }) AfterEach(func() { client.Stop() udpListener.Close() }) It("sends log messages to loggregator", func() { expectedOutput := []byte("Important Testmessage") client.Send(expectedOutput)