func (x *FileAndLoggregatorAccessLogger) Run() {
	for {
		select {
		case record := <-x.channel:
			if x.writer != nil {
				record.WriteTo(x.writer)
			}

			if x.dropsondeSourceInstance != "" && record.ApplicationId() != "" {
				logs.SendAppLog(record.ApplicationId(), record.LogMessage(), "RTR", x.dropsondeSourceInstance)
			}
		case <-x.stopCh:
			return
		}
	}
}
示例#2
0
	"errors"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Logs", func() {
	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")