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


Golang gol.LogMessage類代碼示例

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


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

示例1: 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
	}
}
開發者ID:steenzout,項目名稱:gol,代碼行數:8,代碼來源:example.go

示例2: 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
	}
}
開發者ID:steenzout,項目名稱:gol,代碼行數:11,代碼來源:severity.go

示例3: 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
}
開發者ID:steenzout,項目名稱:gol,代碼行數:13,代碼來源:text.go

示例4: TestTimestamp

func (s *MessageTestSuite) TestTimestamp() {
	var msg *gol.LogMessage

	msg = &gol.LogMessage{"key": "value"}
	v, err := msg.Timestamp()
	assert.Equal(s.T(), fmt.Errorf("Message does not contain field timestamp"), err)
	assert.Nil(s.T(), v)

	msg = gol.NewInfo("key", "value")
	v, err = msg.Timestamp()
	assert.Nil(s.T(), err)
	assert.True(s.T(), v.Before(time.Now()))
}
開發者ID:steenzout,項目名稱:gol,代碼行數:13,代碼來源:messages_test.go

示例5: Filter

// Filter performs a filter check on the given message.
// Returns whether or not a given message should be filtered.
func (f Threshold) Filter(msg *gol.LogMessage) bool {
	var start *time.Time
	var stop *time.Time
	var err error

	if start, err = msg.Start(); err != nil {
		return true
	}
	if stop, err = msg.Stop(); err != nil {
		return true
	}

	return stop.Sub(*start) >= f.threshold
}
開發者ID:steenzout,項目名稱:gol,代碼行數:16,代碼來源:threshold.go

示例6: TestGet

func (s *MessageTestSuite) TestGet() {
	msg := gol.LogMessage{
		"key": "value",
	}

	assert.Equal(s.T(), msg["key"], "value")

	v, err := msg.Get("key")
	assert.Equal(s.T(), "value", v)
	assert.Nil(s.T(), err)

	v, err = msg.Get("unknown")
	assert.Nil(s.T(), v)
	assert.Equal(s.T(), fmt.Errorf("Message does not contain field unknown"), err)
}
開發者ID:steenzout,項目名稱:gol,代碼行數:15,代碼來源:messages_test.go

示例7: 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
		}
	}
}
開發者ID:steenzout,項目名稱:gol,代碼行數:26,代碼來源:example.go

示例8: 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)
	}
}
開發者ID:steenzout,項目名稱:gol,代碼行數:40,代碼來源:syslog.go

示例9: TestGetSetStop

func (s *MessageTestSuite) TestGetSetStop() {
	msg := gol.LogMessage{
		"key": "value",
	}

	v, err := msg.Stop()
	assert.Equal(s.T(), &time.Time{}, v)
	assert.Equal(s.T(), fmt.Errorf("Message does not contain field stop"), err)

	stop := time.Now()
	msg.SetStop(&stop)

	v, err = msg.Stop()
	assert.Equal(s.T(), &stop, v)
	assert.Nil(s.T(), err)
}
開發者ID:steenzout,項目名稱:gol,代碼行數:16,代碼來源:messages_test.go

示例10: 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)
}
開發者ID:steenzout,項目名稱:gol,代碼行數:16,代碼來源:messages_test.go

示例11: TestFieldLength

func (s *MessageTestSuite) TestFieldLength() {
	msg := gol.LogMessage{
		"key": "value",
	}
	assert.Equal(s.T(), 1, msg.FieldLength())
}
開發者ID:steenzout,項目名稱:gol,代碼行數:6,代碼來源:messages_test.go


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