本文整理匯總了Golang中github.com/mediaFORGE/gol.LogMessage.FieldLength方法的典型用法代碼示例。如果您正苦於以下問題:Golang LogMessage.FieldLength方法的具體用法?Golang LogMessage.FieldLength怎麽用?Golang LogMessage.FieldLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mediaFORGE/gol.LogMessage
的用法示例。
在下文中一共展示了LogMessage.FieldLength方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Format
// Format formats the log message.
func (f Custom) Format(msg *gol.LogMessage) (string, error) {
lmsg := msg.FieldLength()
buffer := make([]string, lmsg, lmsg)
i := 0
for k, v := range *msg {
if k != fields.Severity && k != fields.Timestamp {
buffer[i] = fmt.Sprintf("%s:'%s'", k, v)
i += 1
}
}
t, _ := msg.Timestamp()
if severity, err := msg.Severity(); err != nil {
return fmt.Sprintf("%s UNKNOWN %s\n", t.String(), strings.Join(buffer, " ")), nil
} else {
switch severity >= field_severity.Error {
case true:
return fmt.Sprintf("%s %s %s\n", t.String(), color.RedString("%s", severity), strings.Join(buffer, " ")), nil
default:
return fmt.Sprintf("%s %s %s\n", t.String(), severity, strings.Join(buffer, " ")), nil
}
}
}
示例2: Format
// Format formats the log message.
func (f Text) Format(msg *gol.LogMessage) (string, error) {
lmsg := msg.FieldLength()
buffer := make([]string, lmsg, lmsg)
i := 0
for k, v := range *msg {
buffer[i] = fmt.Sprintf("%s=%s", k, v)
i += 1
}
return fmt.Sprintf("%s\n", strings.Join(buffer, " ")), nil
}
示例3: TestFieldLength
func (s *MessageTestSuite) TestFieldLength() {
msg := gol.LogMessage{
"key": "value",
}
assert.Equal(s.T(), 1, msg.FieldLength())
}