本文整理汇总了Golang中github.com/mediaFORGE/gol.LogMessage.Severity方法的典型用法代码示例。如果您正苦于以下问题:Golang LogMessage.Severity方法的具体用法?Golang LogMessage.Severity怎么用?Golang LogMessage.Severity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/mediaFORGE/gol.LogMessage
的用法示例。
在下文中一共展示了LogMessage.Severity方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Filter
func (f *InfoFilter) Filter(msg *gol.LogMessage) bool {
if s, err := msg.Severity(); err != nil {
// no severity
return true
} else {
return s < severity.Warning
}
}
示例3: Filter
// Filter performs a filter check on the given message.
// Returns whether or not a given message should be filtered.
func (f Severity) Filter(msg *gol.LogMessage) bool {
if s, err := msg.Severity(); err != nil {
// no severity
return true
} else {
return s > f.minimum
}
}
示例4: TestGetSetSeverity
func (s *MessageTestSuite) TestGetSetSeverity() {
msg := gol.LogMessage{
"key": "value",
}
v, err := msg.Severity()
assert.Equal(s.T(), severity.Type(-1), v)
assert.Equal(s.T(), fmt.Errorf("Message does not contain field severity"), err)
lvl := severity.Type(severity.Emergency)
msg.SetSeverity(lvl)
v, err = msg.Severity()
assert.Equal(s.T(), lvl, v)
assert.Nil(s.T(), err)
}
示例5: Send
// Send process log message.
func (l *Logger) Send(m *gol.LogMessage) (err error) {
if m == nil {
return
}
if l.Formatter() == nil {
return fmt.Errorf("log formatter is nil")
}
var msg string
if msg, err = l.Formatter().Format(m); err != nil {
return
}
var lvl severity.Type
if lvl, err = m.Severity(); err != nil {
return
}
switch lvl {
case severity.Emergency:
return l.writer.Emerg(msg)
case severity.Alert:
return l.writer.Alert(msg)
case severity.Critical:
return l.writer.Crit(msg)
case severity.Error:
return l.writer.Err(msg)
case severity.Warning:
return l.writer.Warning(msg)
case severity.Notice:
return l.writer.Notice(msg)
case severity.Info:
return l.writer.Info(msg)
case severity.Debug:
return l.writer.Debug(msg)
default:
return l.writer.Info(msg)
}
}