本文整理汇总了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;未经允许,请勿转载。 |
请发表评论