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