Esempio n. 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())
}
Esempio n. 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())
}
Esempio n. 3
0
// 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
}
Esempio n. 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)
}
Esempio n. 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()))
}
Esempio n. 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)
	}
}
Esempio n. 7
0
// NewCritical builds a critical severity message.
func NewCritical(args ...interface{}) *LogMessage {
	return NewMessage(field_severity.Type(field_severity.Critical), args...)
}
Esempio n. 8
0
// NewAlert builds an alert severity message.
func NewAlert(args ...interface{}) *LogMessage {
	return NewMessage(field_severity.Type(field_severity.Alert), args...)
}
Esempio n. 9
0
// NewEmergency builds an emergency severity message.
func NewEmergency(args ...interface{}) *LogMessage {
	return NewMessage(field_severity.Type(field_severity.Emergency), args...)
}
Esempio n. 10
0
// NewDebug builds a debug severity message.
func NewDebug(args ...interface{}) *LogMessage {
	return NewMessage(field_severity.Type(field_severity.Debug), args...)
}
Esempio n. 11
0
// NewInfo builds an info severity message.
func NewInfo(args ...interface{}) *LogMessage {
	return NewMessage(field_severity.Type(field_severity.Info), args...)
}
Esempio n. 12
0
// NewNotice builds a notice severity message.
func NewNotice(args ...interface{}) *LogMessage {
	return NewMessage(field_severity.Type(field_severity.Notice), args...)
}
Esempio n. 13
0
// NewWarning builds a warning severity message.
func NewWarning(args ...interface{}) *LogMessage {
	return NewMessage(field_severity.Type(field_severity.Warning), args...)
}
Esempio n. 14
0
// NewError builds an error severity message.
func NewError(args ...interface{}) *LogMessage {
	return NewMessage(field_severity.Type(field_severity.Error), args...)
}
Esempio n. 15
0
func (s *FilterTestSuite) TestFilterNoSeverityField() {
	f := filter.New(field.Type(field.Debug))
	assert.True(s.T(), f.Filter(&gol.LogMessage{}))
}