Ejemplo n.º 1
0
func (e *LoggregatorEmitter) EmitLogMessage(logMessage *events.LogMessage) {
	messages := splitMessage(string(logMessage.GetMessage()))

	for _, message := range messages {
		if isEmpty(message) {
			continue
		}

		if len(message) > MAX_MESSAGE_BYTE_SIZE {
			logMessage.Message = append([]byte(message)[0:TRUNCATED_OFFSET], TRUNCATED_BYTES...)
		} else {
			logMessage.Message = []byte(message)
		}

		logEnvelope, err := e.newLogEnvelope(*logMessage.AppId, logMessage)
		if err != nil {
			e.logger.Errorf("Error creating envelope: %s", err)
			return
		}
		marshalledLogEnvelope, err := proto.Marshal(logEnvelope)
		if err != nil {
			e.logger.Errorf("Error marshalling envelope: %s", err)
			return
		}
		e.LoggregatorClient.Send(marshalledLogEnvelope)
	}
}
Ejemplo n.º 2
0
func simpleLogMessageOutput(logMsg *events.LogMessage) (msgText string) {
	msgText = string(logMsg.GetMessage())
	reg, err := regexp.Compile("[\n\r]+$")
	if err != nil {
		return
	}
	msgText = reg.ReplaceAllString(msgText, "")
	return
}
Ejemplo n.º 3
0
func messagePriorityValue(msg *events.LogMessage) int {
	switch msg.GetMessageType() {
	case events.LogMessage_OUT:
		return 14
	case events.LogMessage_ERR:
		return 11
	default:
		return -1
	}
}
Ejemplo n.º 4
0
func convertToOldFormat(message *events.LogMessage) *logmessage.LogMessage {
	return &logmessage.LogMessage{
		Message:     message.Message,
		AppId:       message.AppId,
		MessageType: logmessage.LogMessage_MessageType(message.GetMessageType()).Enum(),
		SourceName:  message.SourceType,
		SourceId:    message.SourceInstance,
		Timestamp:   message.Timestamp,
	}
}
Ejemplo n.º 5
0
func ExtractNoaaLogContent(logMsg *events.LogMessage, logHeader string) (logContent string) {
	msgText := string(logMsg.GetMessage())
	msgText = newLinesPattern.ReplaceAllString(msgText, "")

	msgLines := strings.Split(msgText, "\n")
	padding := strings.Repeat(" ", utf8.RuneCountInString(logHeader))
	coloringFunc := terminal.LogStdoutColor
	logType := "OUT"

	if logMsg.GetMessageType() == events.LogMessage_ERR {
		coloringFunc = terminal.LogStderrColor
		logType = "ERR"
	}

	logContent = fmt.Sprintf("%s %s", logType, msgLines[0])
	for _, msgLine := range msgLines[1:] {
		logContent = fmt.Sprintf("%s\n%s%s", logContent, padding, msgLine)
	}
	logContent = coloringFunc(logContent)

	return
}
func ChugLogMessage(logMessage *events.LogMessage) Entry {
	entry := Entry{
		IsLager:    false,
		LogMessage: logMessage,
		Raw:        logMessage.GetMessage(),
	}

	rawString := string(entry.Raw)
	idx := strings.Index(rawString, "{")
	if idx == -1 {
		return entry
	}

	var lagerLog lager.LogFormat
	decoder := json.NewDecoder(strings.NewReader(rawString[idx:]))
	err := decoder.Decode(&lagerLog)
	if err != nil {
		return entry
	}

	entry.Log, entry.IsLager = convertLagerLog(lagerLog)

	return entry
}
Ejemplo n.º 7
0
func getMsgString(message *events.LogMessage) string {
	return string(message.GetMessage())
}
Ejemplo n.º 8
0
func (s *SyslogSink) sendLogMessage(logMessage *events.LogMessage) error {
	_, err := s.syslogWriter.Write(messagePriorityValue(logMessage), logMessage.GetMessage(), logMessage.GetSourceType(), logMessage.GetSourceInstance(), *logMessage.Timestamp)
	return err
}
Ejemplo n.º 9
0
		JustBeforeEach(func() {
			logMessages, errors = cnsmr.TailingLogsWithoutReconnect(appGuid, authToken)
		})

		AfterEach(func() {
			cnsmr.Close()
			Eventually(logMessages).Should(BeClosed())
		})

		Context("when there is no TLS Config or consumerProxyFunc setting", func() {
			Context("when the connection can be established", func() {
				It("returns a read only LogMessage chan and error chan", func() {
					fakeHandler.InputChan <- marshalMessage(createMessage("hello", 0))

					var message *events.LogMessage
					Eventually(logMessages).Should(Receive(&message))
					Expect(message.GetMessage()).To(Equal([]byte("hello")))
					Consistently(errors).ShouldNot(Receive())
				})

				It("receives messages on the incoming channel", func(done Done) {
					fakeHandler.InputChan <- marshalMessage(createMessage("hello", 0))

					message := <-logMessages

					Expect(message.GetMessage()).To(Equal([]byte("hello")))
					fakeHandler.Close()

					close(done)
				})
func (ctlo *ConsoleTailedLogsOutputter) rawDebugLogCallback(log *events.LogMessage) {
	timeString := time.Unix(0, log.GetTimestamp()).Format("01/02 15:04:05.00")
	logOutput := fmt.Sprintf("%s [%s|%s] %s", timeString, log.GetSourceType(), log.GetSourceInstance(), log.GetMessage())
	ctlo.outputChan <- logOutput
}