当前位置: 首页>>代码示例>>Golang>>正文


Golang loggertesthelper.Logger函数代码示例

本文整理汇总了Golang中github.com/cloudfoundry/loggregatorlib/loggertesthelper.Logger函数的典型用法代码示例。如果您正苦于以下问题:Golang Logger函数的具体用法?Golang Logger怎么用?Golang Logger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Logger函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestDrainForReturnsOnly

func TestDrainForReturnsOnly(t *testing.T) {
	groupedSinks := NewGroupedSinks()
	target := "789"

	sink1 := sinks.NewSyslogSink(target, "other sink", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))
	sink2 := sinks.NewSyslogSink(target, "sink we are searching for", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))

	groupedSinks.Register(sink1)
	groupedSinks.Register(sink2)

	sinkDrain := groupedSinks.DrainFor(target, "sink we are searching for")
	assert.Equal(t, sink2, sinkDrain)
}
开发者ID:james-masson,项目名称:loggregator,代码行数:13,代码来源:grouped_sinks_test.go

示例2: TestDumpForReturnsOnlyDumpsForTheGivenAppId

func TestDumpForReturnsOnlyDumpsForTheGivenAppId(t *testing.T) {
	groupedSinks := NewGroupedSinks()
	target := "789"
	otherTarget := "790"

	sink1 := sinks.NewDumpSink(target, 5, loggertesthelper.Logger(), make(chan sinks.Sink, 1), time.Second)
	sink2 := sinks.NewDumpSink(otherTarget, 5, loggertesthelper.Logger(), make(chan sinks.Sink, 1), time.Second)

	groupedSinks.Register(sink1)
	groupedSinks.Register(sink2)

	appSink := groupedSinks.DumpFor(target)
	assert.Equal(t, appSink, sink1)
}
开发者ID:james-masson,项目名称:loggregator,代码行数:14,代码来源:grouped_sinks_test.go

示例3: TestOutgoingProxyConfigWithEmptyAZ

func TestOutgoingProxyConfigWithEmptyAZ(t *testing.T) {
	config := &Config{
		Loggregators: map[string][]string{
			"z1": []string{"10.244.0.14"},
			"z2": []string{},
		},
	}

	assert.NotPanics(t, func() {
		makeOutgoingProxy("0.0.0.0", config, loggertesthelper.Logger())
	})

	hashers := makeHashers(config.Loggregators, 3456, loggertesthelper.Logger())
	assert.Equal(t, len(hashers), 1)
}
开发者ID:uabassguy,项目名称:loggregator,代码行数:15,代码来源:main_test.go

示例4: TestDumpForReturnsOnyDumps

func TestDumpForReturnsOnyDumps(t *testing.T) {
	groupedSinks := NewGroupedSinks()
	target := "789"

	sink1 := sinks.NewSyslogSink(target, "url1", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))
	sink2 := sinks.NewSyslogSink(target, "url2", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))
	sink3 := sinks.NewDumpSink(target, 5, loggertesthelper.Logger(), make(chan sinks.Sink, 1), time.Second)

	groupedSinks.Register(sink1)
	groupedSinks.Register(sink2)
	groupedSinks.Register(sink3)

	appSink := groupedSinks.DumpFor(target)
	assert.Equal(t, appSink, sink3)
}
开发者ID:james-masson,项目名称:loggregator,代码行数:15,代码来源:grouped_sinks_test.go

示例5: TestDumpForReturnsOnyDumps

func TestDumpForReturnsOnyDumps(t *testing.T) {
	groupedSinks := NewGroupedSinks()
	target := "789"

	sink1 := sinks.NewSyslogSink(target, "url1", loggertesthelper.Logger(), syslogWriter)
	sink2 := sinks.NewSyslogSink(target, "url2", loggertesthelper.Logger(), syslogWriter)
	sink3 := sinks.NewDumpSink(target, 5, loggertesthelper.Logger())

	groupedSinks.Register(sink1)
	groupedSinks.Register(sink2)
	groupedSinks.Register(sink3)

	appSink := groupedSinks.DumpFor(target)
	assert.Equal(t, appSink, sink3)
}
开发者ID:uabassguy,项目名称:loggregator,代码行数:15,代码来源:grouped_sinks_test.go

示例6: TestThatItDoesNotCreateAnotherSyslogDrainIfItIsAlreadyThere

func TestThatItDoesNotCreateAnotherSyslogDrainIfItIsAlreadyThere(t *testing.T) {
	logger := loggertesthelper.Logger()
	sinkManager := NewSinkManager(1024, false, nil, logger)
	oldActiveSyslogSinksCounter := sinkManager.Metrics.SyslogSinks
	go sinkManager.Start()

	incomingLogChan := make(chan []byte, 10)
	testMessageRouter := NewMessageRouter(incomingLogChan, testhelpers.UnmarshallerMaker("secret"), sinkManager, 2048, logger)

	go testMessageRouter.Start()
	ourSink := testSink{make(chan *logmessage.Message, 100), false}
	sinkManager.sinkOpenChan <- ourSink
	<-time.After(1 * time.Millisecond)

	message := messagetesthelpers.NewMessage(t, "error msg", "appId")
	message.GetLogMessage().DrainUrls = []string{"http://10.10.123.1"}
	testMessageRouter.outgoingLogChan <- message
	waitForMessageGettingProcessed(t, ourSink, 10*time.Millisecond)

	assert.Equal(t, sinkManager.Metrics.SyslogSinks, oldActiveSyslogSinksCounter+1)

	testMessageRouter.outgoingLogChan <- message
	waitForMessageGettingProcessed(t, ourSink, 10*time.Millisecond)

	assert.Equal(t, sinkManager.Metrics.SyslogSinks, oldActiveSyslogSinksCounter+1)
}
开发者ID:james-masson,项目名称:loggregator,代码行数:26,代码来源:message_router_test.go

示例7: TestDumpWithLotsOfMessagesAndLargeBuffer

func TestDumpWithLotsOfMessagesAndLargeBuffer(t *testing.T) {
	dump := NewDumpSink("myApp", 200, loggertesthelper.Logger(), make(chan Sink, 1), time.Second)

	go dump.Run()

	for i := 0; i < 1000; i++ {
		logMessage := messagetesthelpers.NewMessage(t, strconv.Itoa(i), "appId")
		dump.Channel() <- logMessage
	}

	runtime.Gosched()

	logMessages := dump.Dump()
	assert.Equal(t, len(logMessages), 200)
	assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "800")
	assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "801")

	for i := 1000; i < 2000; i++ {
		logMessage := messagetesthelpers.NewMessage(t, strconv.Itoa(i), "appId")
		dump.Channel() <- logMessage
	}

	runtime.Gosched()

	logMessages = dump.Dump()
	assert.Equal(t, len(logMessages), 200)
	assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "1800")
	assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "1801")

	logMessages = dump.Dump()
	assert.Equal(t, len(logMessages), 200)
	assert.Equal(t, string(logMessages[0].GetLogMessage().GetMessage()), "1800")
	assert.Equal(t, string(logMessages[1].GetLogMessage().GetMessage()), "1801")
}
开发者ID:james-masson,项目名称:loggregator,代码行数:34,代码来源:dump_sink_test.go

示例8: TestThatARemovedTaskWillBeRemoved

func TestThatARemovedTaskWillBeRemoved(t *testing.T) {
	writeToFile(t, `{"instances": [{"state": "RUNNING", "instance_index": 123}]}`, true)
	agent := &agent{filePath(), loggertesthelper.Logger()}

	tasksChan := agent.watchInstancesJsonFileForChanges()

	inst, ok := <-tasksChan
	assert.True(t, ok, "Channel is closed")
	assert.NotNil(t, inst)

	os.Remove(filePath())

	select {
	case inst = <-tasksChan:
		t.Errorf("We just got an old task: %v", inst)
	case <-time.After(2 * time.Millisecond):
		// OK
	}

	writeToFile(t, `{"instances": [{"state": "RUNNING", "instance_index": 1234}]}`, true)

	inst, ok = <-tasksChan
	assert.True(t, ok, "Channel is closed")

	expectedInst := task{index: 1234, sourceName: "App"}
	assert.Equal(t, expectedInst, inst)
}
开发者ID:james-masson,项目名称:loggregator,代码行数:27,代码来源:agent_test.go

示例9: TestProxyingWithHashingBetweenServers

func TestProxyingWithHashingBetweenServers(t *testing.T) {
	go Server("localhost:62024", "Hello World from the server 1", 1)
	go Server("localhost:62025", "Hello World from the server 2", 1)

	proxy := NewProxy(
		"localhost:62026",
		[]*hasher.Hasher{hasher.NewHasher([]string{"localhost:62024", "localhost:62025"})},
		testhelpers.SuccessfulAuthorizer,
		loggertesthelper.Logger(),
	)
	go proxy.Start()
	WaitForServerStart("62024", "/")

	receivedChan := Client(t, "62026", "/?app=0")

	select {
	case data := <-receivedChan:
		assert.Equal(t, string(data), "Hello World from the server 1")
	case <-time.After(1 * time.Second):
		t.Error("Did not receive response within one second")
	}

	receivedChan = Client(t, "62026", "/?app=1")

	select {
	case data := <-receivedChan:
		assert.Equal(t, string(data), "Hello World from the server 2")
	case <-time.After(1 * time.Second):
		t.Error("Did not receive response within one second")
	}
}
开发者ID:james-masson,项目名称:loggregator,代码行数:31,代码来源:output_proxy_test.go

示例10: TestProxyWithoutAuthorization

func TestProxyWithoutAuthorization(t *testing.T) {
	proxy := NewProxy(
		"localhost:62061",
		[]*hasher.Hasher{
			hasher.NewHasher([]string{"localhost:62032"}),
		},
		testhelpers.SuccessfulAuthorizer,
		loggertesthelper.Logger(),
	)
	go proxy.Start()
	time.Sleep(time.Millisecond * 50)

	config, err := websocket.NewConfig("ws://localhost:62061/?app=myApp", "http://localhost")
	assert.NoError(t, err)
	receivedChan := ClientWithAuth(t, "62061", "/?app=myApp", config)

	select {
	case data := <-receivedChan:
		messagetesthelpers.AssertProtoBufferMessageEquals(t, "Error: Authorization not provided", data)
	case <-time.After(1 * time.Second):
		t.Error("Did not receive response within one second")
	}

	_, stillOpen := <-receivedChan
	assert.False(t, stillOpen)
}
开发者ID:james-masson,项目名称:loggregator,代码行数:26,代码来源:output_proxy_test.go

示例11: TestThatWeListenToStdErrUnixSocket

func TestThatWeListenToStdErrUnixSocket(t *testing.T) {
	tmpdir, err := ioutil.TempDir("", "testing")
	assert.NoError(t, err)
	defer os.RemoveAll(tmpdir)

	instance := &instance{
		applicationId:       "1234",
		wardenJobId:         56,
		wardenContainerPath: tmpdir,
		index:               4,
		drainUrls:           []string{"syslog://10.20.30.40:8050"}}
	os.MkdirAll(instance.identifier(), 0777)

	stdoutSocketPath := filepath.Join(instance.identifier(), "stdout.sock")
	stderrSocketPath := filepath.Join(instance.identifier(), "stderr.sock")
	os.Remove(stdoutSocketPath)
	os.Remove(stderrSocketPath)
	stdoutListener, err := net.Listen("unix", stdoutSocketPath)
	defer stdoutListener.Close()
	assert.NoError(t, err)
	stderrListener, err := net.Listen("unix", stderrSocketPath)
	defer stderrListener.Close()
	assert.NoError(t, err)

	expectedMessage := "Some Output\n"
	secondLogMessage := "toally different\n"

	mockLoggregatorEmitter := new(MockLoggregatorEmitter)

	mockLoggregatorEmitter.received = make(chan *logmessage.LogMessage)
	instance.startListening(mockLoggregatorEmitter, loggertesthelper.Logger())

	connection, err := stderrListener.Accept()
	defer connection.Close()
	assert.NoError(t, err)

	_, err = connection.Write([]byte(expectedMessage))
	assert.NoError(t, err)

	receivedMessage := <-mockLoggregatorEmitter.received

	assert.Equal(t, "1234", receivedMessage.GetAppId())
	assert.Equal(t, logmessage.LogMessage_WARDEN_CONTAINER, receivedMessage.GetSourceType())
	assert.Equal(t, logmessage.LogMessage_ERR, receivedMessage.GetMessageType())
	assert.Equal(t, expectedMessage, string(receivedMessage.GetMessage()))
	assert.Equal(t, []string{"syslog://10.20.30.40:8050"}, receivedMessage.GetDrainUrls())
	assert.Equal(t, "4", receivedMessage.GetSourceId())

	_, err = connection.Write([]byte(secondLogMessage))
	assert.NoError(t, err)

	receivedMessage = <-mockLoggregatorEmitter.received

	assert.Equal(t, "1234", receivedMessage.GetAppId())
	assert.Equal(t, logmessage.LogMessage_WARDEN_CONTAINER, receivedMessage.GetSourceType())
	assert.Equal(t, logmessage.LogMessage_ERR, receivedMessage.GetMessageType())
	assert.Equal(t, secondLogMessage, string(receivedMessage.GetMessage()))
	assert.Equal(t, []string{"syslog://10.20.30.40:8050"}, receivedMessage.GetDrainUrls())
	assert.Equal(t, "4", receivedMessage.GetSourceId())
}
开发者ID:uabassguy,项目名称:loggregator,代码行数:60,代码来源:instance_test.go

示例12: TestSysLoggerComesUpLate

func TestSysLoggerComesUpLate(t *testing.T) {
	sysLogger := NewSyslogWriterRecorder()
	sysLogger.SetUp(false)
	sink := NewSyslogSink("appId", "url_not_used", loggertesthelper.Logger(), sysLogger)

	done := make(chan bool)
	go func() {
		sink.Run()
		done <- true
	}()

	for i := 0; i < 15; i++ {
		msg := fmt.Sprintf("message no %v", i)
		logMessage := messagetesthelpers.NewMessage(t, msg, "appId")

		sink.Channel() <- logMessage
	}
	close(sink.Channel())

	sysLogger.SetUp(true)
	<-done

	data := sysLogger.ReceivedMessages()
	assert.Equal(t, len(data), 10)

	for i := 0; i < 10; i++ {
		msg := fmt.Sprintf("out: message no %v", i+5)
		assert.Equal(t, data[i], msg)
	}
}
开发者ID:uabassguy,项目名称:loggregator,代码行数:30,代码来源:syslog_sink_test.go

示例13: TestDelete

func TestDelete(t *testing.T) {
	groupedSinks := NewGroupedSinks()
	target := "789"

	sink1 := sinks.NewSyslogSink(target, "url1", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))
	sink2 := sinks.NewSyslogSink(target, "url2", loggertesthelper.Logger(), DummySyslogWriter{}, make(chan<- *logmessage.Message))

	groupedSinks.Register(sink1)
	groupedSinks.Register(sink2)

	groupedSinks.Delete(sink1)

	appSinks := groupedSinks.For(target)
	assert.Equal(t, len(appSinks), 1)
	assert.Equal(t, appSinks[0], sink2)
}
开发者ID:james-masson,项目名称:loggregator,代码行数:16,代码来源:grouped_sinks_test.go

示例14: TestProxyingWithMultipleAZs

func TestProxyingWithMultipleAZs(t *testing.T) {
	go Server("localhost:62027", "Hello World from the server 1 - AZ1", 1)
	go Server("localhost:62028", "Hello World from the server 2 - AZ1", 1)
	go Server("localhost:62029", "Hello World from the server 1 - AZ2", 1)
	go Server("localhost:62030", "Hello World from the server 2 - AZ2", 1)

	proxy := NewProxy(
		"localhost:62031",
		[]*hasher.Hasher{
			hasher.NewHasher([]string{"localhost:62027", "localhost:62028"}),
			hasher.NewHasher([]string{"localhost:62029", "localhost:62030"}),
		},
		testhelpers.SuccessfulAuthorizer,
		loggertesthelper.Logger(),
	)
	go proxy.Start()
	WaitForServerStart("62027", "/")

	receivedChan := Client(t, "62031", "/?app=0")
	messages := ""
	for message := range receivedChan {
		messages = messages + string(message)
	}
	assert.Contains(t, messages, "Hello World from the server 1 - AZ1")
	assert.Contains(t, messages, "Hello World from the server 1 - AZ2")

	receivedChan = Client(t, "62031", "/?app=1")
	messages = ""
	for message := range receivedChan {
		messages = messages + string(message)
	}
	assert.Contains(t, messages, "Hello World from the server 2 - AZ1")
	assert.Contains(t, messages, "Hello World from the server 2 - AZ2")
}
开发者ID:james-masson,项目名称:loggregator,代码行数:34,代码来源:output_proxy_test.go

示例15: TestKeepAliveWithMultipleAZs

func TestKeepAliveWithMultipleAZs(t *testing.T) {
	keepAliveChan1 := make(chan []byte)
	keepAliveChan2 := make(chan []byte)
	go KeepAliveServer("localhost:62032", keepAliveChan1)
	go KeepAliveServer("localhost:62033", keepAliveChan2)

	proxy := NewProxy(
		"localhost:62034",
		[]*hasher.Hasher{
			hasher.NewHasher([]string{"localhost:62032"}),
			hasher.NewHasher([]string{"localhost:62033"}),
		},
		testhelpers.SuccessfulAuthorizer,
		loggertesthelper.Logger(),
	)
	go proxy.Start()
	WaitForServerStart("62032", "/")

	KeepAliveClient(t, "62034", "/?app=myServerApp1")

	select {
	case data := <-keepAliveChan1:
		assert.Equal(t, string(data), "keep alive")
	case <-time.After(1 * time.Second):
		t.Error("Did not receive response within one second")
	}
	select {
	case data := <-keepAliveChan2:
		assert.Equal(t, string(data), "keep alive")
	case <-time.After(1 * time.Second):
		t.Error("Did not receive response within one second")
	}
}
开发者ID:james-masson,项目名称:loggregator,代码行数:33,代码来源:output_proxy_test.go


注:本文中的github.com/cloudfoundry/loggregatorlib/loggertesthelper.Logger函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。