func main() { log.Send(&gol.LogMessage{"hello": "world!"}) log.Send(gol.NewError("error", "info")) log.Send(gol.NewDebug("debug", "info")) errorLog.Send(&gol.LogMessage{"hello": "world!"}) errorLog.Send(gol.NewEmergency("emergency", "errorLog")) errorLog.Send(gol.NewError("error", "errorLog")) errorLog.Send(gol.NewWarning("error", "errorLog")) errorLog.Send(gol.NewInfo("info", "errorLog")) errorLog.Send(gol.NewDebug("debug", "errorLog")) }
func (s *LoggerTestSuite) TestSendNilFormatter() { msg := gol.NewDebug() mf := &mock.LogFilter{} mf.Mock.On("Filter", msg).Return(false, nil) logger := simple.New(mf, nil, nil) assert.Error(s.T(), logger.Send(msg)) }
func (s *LoggerTestSuite) TestSendFormatError() { msg := gol.NewDebug() mf := &mock.LogFilter{} mf.Mock.On("Filter", msg).Return(false, nil) mfmt := &mock.LogFormatter{} mfmt.Mock.On("Format", msg).Return("", fmt.Errorf("unknown")) logger := simple.New(mf, mfmt, nil) assert.Error(s.T(), logger.Send(msg)) }
func main() { // this will be written to stderr logger.Send(gol.NewEmergency("message", "system is down")) logger.Send(gol.NewAlert("message", "failed to write to disk")) logger.Send(gol.NewCritical("message", "high server load")) logger.Send(gol.NewError("message", "invalid number format")) // this will not be written anywhere logger.Send(gol.NewWarning("message", "performance close to 1s threshold")) logger.Send(gol.NewNotice("message", "failed to communicate with monitoring service")) logger.Send(gol.NewInfo("message", "requested processed in 250ms")) logger.Send(gol.NewDebug("debug", "var x = 10")) }
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())) }