示例#1
0
func (s *SeverityTestSuite) TestTypeValidate() {
	assert.NotNil(s.T(), severity.Type(-1).Validate())

	for i := 0; i < 8; i++ {
		assert.Nil(s.T(), severity.Type(i).Validate())
	}

	assert.NotNil(s.T(), severity.Type(8).Validate())
}
示例#2
0
func (s *SeverityTestSuite) TestTypeString() {
	assert.Equal(s.T(), "UNKNOWN", severity.Type(-1).String())

	assert.Equal(s.T(), "EMERGENCY", severity.Type(severity.Emergency).String())
	assert.Equal(s.T(), "ALERT", severity.Type(severity.Alert).String())
	assert.Equal(s.T(), "CRITICAL", severity.Type(severity.Critical).String())
	assert.Equal(s.T(), "ERROR", severity.Type(severity.Error).String())
	assert.Equal(s.T(), "WARNING", severity.Type(severity.Warning).String())
	assert.Equal(s.T(), "NOTICE", severity.Type(severity.Notice).String())
	assert.Equal(s.T(), "INFO", severity.Type(severity.Info).String())
	assert.Equal(s.T(), "DEBUG", severity.Type(severity.Debug).String())

	assert.Equal(s.T(), "UNKNOWN", severity.Type(8).String())
}
示例#3
0
文件: messages.go 项目: steenzout/gol
// Severity returns the value of the logger message severity level field.
func (msg LogMessage) Severity() (lvl field_severity.Type, err error) {
	var v interface{}
	if v, err = msg.Get(fields.Severity); err == nil {
		return v.(field_severity.Type), nil
	}
	return field_severity.Type(-1), err
}
示例#4
0
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
0
func (s *FilterTestSuite) TestFilter() {
	f := filter.New(field.Type(field.Emergency))
	cases := []gol.NewLogMessageFunc{
		gol.NewAlert, gol.NewCritical, gol.NewError, gol.NewWarning, gol.NewNotice, gol.NewInfo, gol.NewDebug,
	}

	assert.False(s.T(), f.Filter(gol.NewEmergency()))
	for _, newFunc := range cases {
		assert.True(s.T(), f.Filter(newFunc()))
	}

	f = filter.New(field.Type(field.Debug))
	cases = []gol.NewLogMessageFunc{
		gol.NewEmergency, gol.NewAlert, gol.NewCritical, gol.NewError, gol.NewWarning, gol.NewNotice, gol.NewInfo,
	}

	for _, newFunc := range cases {
		assert.False(s.T(), f.Filter(newFunc()))
	}
	assert.False(s.T(), f.Filter(gol.NewDebug()))
}
示例#6
0
func (s *MessageTestSuite) TestNewSeverity() {
	cases := map[severity.Type]gol.NewLogMessageFunc{
		severity.Emergency: gol.NewEmergency,
		severity.Alert:     gol.NewAlert,
		severity.Critical:  gol.NewCritical,
		severity.Error:     gol.NewError,
		severity.Warning:   gol.NewWarning,
		severity.Notice:    gol.NewNotice,
		severity.Info:      gol.NewInfo,
		severity.Debug:     gol.NewDebug,
	}

	for lvl, f := range cases {
		s.assertSeverityLevel(severity.Type(lvl), f)
	}
}
示例#7
0
文件: messages.go 项目: steenzout/gol
// NewCritical builds a critical severity message.
func NewCritical(args ...interface{}) *LogMessage {
	return NewMessage(field_severity.Type(field_severity.Critical), args...)
}
示例#8
0
文件: messages.go 项目: steenzout/gol
// NewAlert builds an alert severity message.
func NewAlert(args ...interface{}) *LogMessage {
	return NewMessage(field_severity.Type(field_severity.Alert), args...)
}
示例#9
0
文件: messages.go 项目: steenzout/gol
// NewEmergency builds an emergency severity message.
func NewEmergency(args ...interface{}) *LogMessage {
	return NewMessage(field_severity.Type(field_severity.Emergency), args...)
}
示例#10
0
文件: messages.go 项目: steenzout/gol
// NewDebug builds a debug severity message.
func NewDebug(args ...interface{}) *LogMessage {
	return NewMessage(field_severity.Type(field_severity.Debug), args...)
}
示例#11
0
文件: messages.go 项目: steenzout/gol
// NewInfo builds an info severity message.
func NewInfo(args ...interface{}) *LogMessage {
	return NewMessage(field_severity.Type(field_severity.Info), args...)
}
示例#12
0
文件: messages.go 项目: steenzout/gol
// NewNotice builds a notice severity message.
func NewNotice(args ...interface{}) *LogMessage {
	return NewMessage(field_severity.Type(field_severity.Notice), args...)
}
示例#13
0
文件: messages.go 项目: steenzout/gol
// NewWarning builds a warning severity message.
func NewWarning(args ...interface{}) *LogMessage {
	return NewMessage(field_severity.Type(field_severity.Warning), args...)
}
示例#14
0
文件: messages.go 项目: steenzout/gol
// NewError builds an error severity message.
func NewError(args ...interface{}) *LogMessage {
	return NewMessage(field_severity.Type(field_severity.Error), args...)
}
示例#15
0
func (s *FilterTestSuite) TestFilterNoSeverityField() {
	f := filter.New(field.Type(field.Debug))
	assert.True(s.T(), f.Filter(&gol.LogMessage{}))
}