"github.com/cloudfoundry/loggregatorlib/logmessage"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("loggregatorMessage", func() {
	Describe("ToLog", func() {
		var date time.Time

		BeforeEach(func() {
			date = time.Date(2014, 4, 4, 11, 39, 20, 5, time.UTC)
		})

		Context("when the message comes", func() {
			It("include the instance index", func() {
				msg := testlogs.NewLogMessage("Hello World!", "", "DEA", "4", logmessage.LogMessage_OUT, date)
				Expect(terminal.Decolorize(msg.ToLog(time.UTC))).To(Equal("2014-04-04T11:39:20.00+0000 [DEA/4]      OUT Hello World!"))
			})

			It("doesn't include the instance index if sourceID is empty", func() {
				msg := testlogs.NewLogMessage("Hello World!", "", "DEA", "", logmessage.LogMessage_OUT, date)
				Expect(terminal.Decolorize(msg.ToLog(time.UTC))).To(Equal("2014-04-04T11:39:20.00+0000 [DEA]        OUT Hello World!"))
			})
		})

		Context("when the message was written to stderr", func() {
			It("shows the log type as 'ERR'", func() {
				msg := testlogs.NewLogMessage("Hello World!", "", "DEA", "4", logmessage.LogMessage_ERR, date)
				Expect(terminal.Decolorize(msg.ToLog(time.UTC))).To(Equal("2014-04-04T11:39:20.00+0000 [DEA/4]      ERR Hello World!"))
			})
		})
Example #2
0
	Context("when logged in", func() {
		var (
			app models.Application
		)

		BeforeEach(func() {
			requirementsFactory.NewLoginRequirementReturns(requirements.Passing{})
			requirementsFactory.NewTargetedSpaceRequirementReturns(requirements.Passing{})

			app = models.Application{}
			app.Name = "my-app"
			app.GUID = "my-app-guid"

			currentTime := time.Now()
			recentLogs := []logs.Loggable{
				testlogs.NewLogMessage("Log Line 1", app.GUID, "DEA", "1", logmessage.LogMessage_ERR, currentTime),
				testlogs.NewLogMessage("Log Line 2", app.GUID, "DEA", "1", logmessage.LogMessage_ERR, currentTime),
			}

			appLogs := []logs.Loggable{
				testlogs.NewLogMessage("Log Line 1", app.GUID, "DEA", "1", logmessage.LogMessage_ERR, time.Now()),
			}

			applicationReq := new(requirementsfakes.FakeApplicationRequirement)
			applicationReq.GetApplicationReturns(app)
			requirementsFactory.NewApplicationRequirementReturns(applicationReq)

			logsRepo.RecentLogsForReturns(recentLogs, nil)
			logsRepo.TailLogsForStub = func(appGUID string, onConnect func(), logChan chan<- logs.Loggable, errChan chan<- error) {
				onConnect()
				go func() {
Example #3
0
			))
		})

		It("only displays staging logs when an app is starting", func() {
			applicationReq := new(requirementsfakes.FakeApplicationRequirement)
			applicationReq.GetApplicationReturns(defaultAppForStart)
			requirementsFactory.NewApplicationRequirementReturns(applicationReq)
			appRepo.UpdateReturns(defaultAppForStart, nil)
			appRepo.ReadReturns(defaultAppForStart, nil)

			currentTime := time.Now()
			wrongSourceName := "DEA"
			correctSourceName := "STG"

			logMessages.Store([]logs.Loggable{
				testlogs.NewLogMessage("Log Line 1", defaultAppForStart.GUID, wrongSourceName, "1", logmessage.LogMessage_OUT, currentTime),
				testlogs.NewLogMessage("Log Line 2", defaultAppForStart.GUID, correctSourceName, "1", logmessage.LogMessage_OUT, currentTime),
				testlogs.NewLogMessage("Log Line 3", defaultAppForStart.GUID, correctSourceName, "1", logmessage.LogMessage_OUT, currentTime),
				testlogs.NewLogMessage("Log Line 4", defaultAppForStart.GUID, wrongSourceName, "1", logmessage.LogMessage_OUT, currentTime),
			})

			callStart([]string{"my-app"})

			Expect(ui.Outputs()).To(ContainSubstrings(
				[]string{"Log Line 2"},
				[]string{"Log Line 3"},
			))
			Expect(ui.Outputs()).ToNot(ContainSubstrings(
				[]string{"Log Line 1"},
				[]string{"Log Line 4"},
			))