コード例 #1
0
func (destination *streamDestination) flush() {
	msg := destination.copyAndResetBuffer()

	if len(msg) > 0 {
		switch destination.messageType {
		case events.LogMessage_OUT:
			logs.SendAppLog(destination.guid, string(msg), destination.sourceName, destination.sourceId)
		case events.LogMessage_ERR:
			logs.SendAppErrorLog(destination.guid, string(msg), destination.sourceName, destination.sourceId)
		}
	}
}
コード例 #2
0
ファイル: logs_test.go プロジェクト: jungle0755/gorouter
	var fakeLogSender *fake.FakeLogSender

	BeforeEach(func() {
		fakeLogSender = fake.NewFakeLogSender()
		logs.Initialize(fakeLogSender)
	})

	It("delegates SendAppLog", func() {
		logs.SendAppLog("app-id", "custom-log-message", "App", "0")

		Expect(fakeLogSender.GetLogs()).To(HaveLen(1))
		Expect(fakeLogSender.GetLogs()[0]).To(Equal(fake.Log{AppId: "app-id", Message: "custom-log-message", SourceType: "App", SourceInstance: "0", MessageType: "OUT"}))
	})

	It("delegates SendAppErrorLog", func() {
		logs.SendAppErrorLog("app-id", "custom-log-error-message", "App", "0")

		Expect(fakeLogSender.GetLogs()).To(HaveLen(1))
		Expect(fakeLogSender.GetLogs()[0]).To(Equal(fake.Log{AppId: "app-id", Message: "custom-log-error-message", SourceType: "App", SourceInstance: "0", MessageType: "ERR"}))
	})

	Context("when errors occur", func() {
		BeforeEach(func() {
			fakeLogSender.ReturnError = errors.New("error occurred")
		})

		It("SendAppLog returns error", func() {
			err := logs.SendAppLog("app-id", "custom-log-message", "App", "0")
			Expect(err).To(HaveOccurred())
		})