當前位置: 首頁>>代碼示例>>Golang>>正文


Golang logmessage.LogMessage類代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/loggregatorlib/logmessage.LogMessage的典型用法代碼示例。如果您正苦於以下問題:Golang LogMessage類的具體用法?Golang LogMessage怎麽用?Golang LogMessage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了LogMessage類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: extractLogContent

func extractLogContent(logMsg *logmessage.LogMessage, logHeader string) (logContent string) {
	msgText := string(logMsg.GetMessage())
	reg, err := regexp.Compile("[\n\r]+$")
	if err == nil {
		msgText = reg.ReplaceAllString(msgText, "")
	}

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

	if logMsg.GetMessageType() == logmessage.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
}
開發者ID:jalateras,項目名稱:cli,代碼行數:25,代碼來源:helpers.go

示例2: EmitLogMessage

func (e *LoggregatorEmitter) EmitLogMessage(logMessage *logmessage.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)
		}
		if e.sharedSecret == "" {
			marshalledLogMessage, err := proto.Marshal(logMessage)
			if err != nil {
				e.logger.Errorf("Error marshalling message: %s", err)
				return
			}
			e.LoggregatorClient.Send(marshalledLogMessage)
		} else {
			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)
		}
	}
}
開發者ID:KeyOfSpectator,項目名稱:gorouter,代碼行數:35,代碼來源:emit.go

示例3: simpleLogMessageOutput

func simpleLogMessageOutput(logMsg *logmessage.LogMessage) (msgText string) {
	msgText = string(logMsg.GetMessage())
	reg, err := regexp.Compile("[\n\r]+$")
	if err != nil {
		return
	}
	msgText = reg.ReplaceAllString(msgText, "")
	return
}
開發者ID:nota-ja,項目名稱:cli,代碼行數:9,代碼來源:start.go

示例4: createMessage

func createMessage(t *testing.T, protoMsg *logmessage.LogMessage, sourceName *string, msgType *logmessage.LogMessage_MessageType) (msg *logmessage.Message) {
	protoMsg.SourceName = sourceName
	protoMsg.MessageType = msgType

	data, err := proto.Marshal(protoMsg)
	assert.NoError(t, err)

	msg, err = logmessage.ParseMessage(data)
	assert.NoError(t, err)

	return
}
開發者ID:nsnt,項目名稱:cli,代碼行數:12,代碼來源:helpers_test.go

示例5: createMessage

func createMessage(protoMsg *logmessage.LogMessage, sourceName *string, msgType *logmessage.LogMessage_MessageType) (msg *logmessage.Message) {
	protoMsg.SourceName = sourceName
	protoMsg.MessageType = msgType

	data, err := proto.Marshal(protoMsg)
	Expect(err).NotTo(HaveOccurred())

	msg, err = logmessage.ParseMessage(data)
	Expect(err).NotTo(HaveOccurred())

	return
}
開發者ID:knolleary,項目名稱:cli,代碼行數:12,代碼來源:helpers_test.go

示例6: ParseLogMessages

// ParseLogMessages is a modified version of httpRecent.
// https://github.com/cloudfoundry/loggregator_consumer/blob/89d7fe237afae1e8222554359ec03b72c8466d10/consumer.go#L145
// Also, when using their Recent function, we would get unauthorized errors. If we make the request ourselves, it works.
// TODO eventually figure out the cause of the unauthorized errors
func (c *LogContext) ParseLogMessages(body *io.ReadCloser, contentType string) (*bytes.Buffer, error) {
	_, params, err := mime.ParseMediaType(contentType)
	if err != nil {
		return nil, err
	}

	var msg logmessage.LogMessage
	reader := multipart.NewReader(*body, params["boundary"])
	var buffer bytes.Buffer
	var messages bytes.Buffer
	firstNotInserted := true
	messages.WriteRune('[')
	for part, loopErr := reader.NextPart(); loopErr == nil; part, loopErr = reader.NextPart() {
		// Skip putting a comma if we haven't put the first element in there yet.
		if !firstNotInserted {
			messages.WriteRune(',')
		} else {
			firstNotInserted = false
		}

		// Clear out temporary buffer.
		buffer.Reset()

		msg = logmessage.LogMessage{}
		// Read raw bytes.
		_, err := buffer.ReadFrom(part)
		if err != nil {
			break
		}
		// Try to unmarshal the bytes into a LogMessage struct.
		proto.Unmarshal(buffer.Bytes(), &msg)
		// Marshal the data into json with only the Message.
		json, err := json.Marshal(struct {
			Message string `json:"message"`
		}{
			Message: string(msg.GetMessage()),
		})
		// Write it to our buffer.
		messages.Write(json)
		part.Close()
	}
	messages.WriteRune(']')
	buffer.Reset()
	return &messages, nil
}
開發者ID:ArthurHlt,項目名稱:cg-deck,代碼行數:49,代碼來源:log.go

示例7: ExtractLogContent

func ExtractLogContent(logMsg *logmessage.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() == logmessage.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
}
開發者ID:vframbach,項目名稱:cli,代碼行數:22,代碼來源:logs.go

示例8: getLoggregatorMsgString

func getLoggregatorMsgString(message *logmessage.LogMessage) string {
	return string(message.GetMessage())
}
開發者ID:tools-alexuser01,項目名稱:cli,代碼行數:3,代碼來源:log_message_queue_old_loggregator_test.go

示例9:

	Context("Streaming", func() {
		It("delivers legacy format messages at legacy endpoint", func() {
			legacy_consumer := loggregator_consumer.New(legacyEndpoint, &tls.Config{}, nil)
			messages, err := legacy_consumer.Tail(APP_ID, AUTH_TOKEN)
			Expect(err).NotTo(HaveOccurred())
			var request *http.Request
			Eventually(fakeDoppler.TrafficControllerConnected, 10).Should(Receive(&request))

			Expect(request.URL.Path).To(Equal("/apps/1234/stream"))

			currentTime := time.Now().UnixNano()
			dropsondeMessage := makeDropsondeMessage("Make me Legacy Format", APP_ID, currentTime)
			fakeDoppler.SendLogMessage(dropsondeMessage)

			var receivedMessage *logmessage.LogMessage
			Eventually(messages).Should(Receive(&receivedMessage))

			Expect(receivedMessage.GetMessage()).To(BeEquivalentTo("Make me Legacy Format"))
			Expect(receivedMessage.GetAppId()).To(Equal(APP_ID))
			Expect(receivedMessage.GetTimestamp()).To(Equal(currentTime))

			legacy_consumer.Close()
		})
	})

	Context("Recent", func() {
		It("returns a multi-part HTTP response with all recent messages", func() {
			const messageLength = 5
			expectedMessages := make([][]byte, messageLength)
開發者ID:yingkitw,項目名稱:loggregator,代碼行數:29,代碼來源:legacy_end_to_end_test.go

示例10:

			LogMessage: &events.LogMessage{
				Message:        message,
				MessageType:    events.LogMessage_OUT.Enum(),
				Timestamp:      proto.Int64(1234),
				AppId:          proto.String("AppId"),
				SourceType:     proto.String("SRC"),
				SourceInstance: proto.String("0"),
			},
		}

		bytes, _ := proto.Marshal(envelope)
		msg, err := marshaller.TranslateDropsondeToLegacyLogMessage(bytes)

		Expect(err).To(BeNil())

		var legacyMessage logmessage.LogMessage
		proto.Unmarshal(msg, &legacyMessage)
		Expect(legacyMessage.GetMessage()).To(Equal(message))
		Expect(legacyMessage.GetAppId()).To(Equal("AppId"))
		Expect(legacyMessage.GetSourceName()).To(Equal("SRC"))
		Expect(legacyMessage.GetSourceId()).To(Equal("0"))
		Expect(legacyMessage.GetTimestamp()).To(BeNumerically("==", 1234))
	})

	It("returns an error if it fails to unmarshall the envelope", func() {
		junk := []byte{1, 2, 3}

		msg, err := marshaller.TranslateDropsondeToLegacyLogMessage(junk)

		Expect(msg).To(BeNil())
		Expect(err.Error()).To(ContainSubstring("Unable to unmarshal"))
開發者ID:lyuyun,項目名稱:loggregator,代碼行數:31,代碼來源:legacy_log_translator_test.go


注:本文中的github.com/cloudfoundry/loggregatorlib/logmessage.LogMessage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。