コード例 #1
0
ファイル: handlers_test.go プロジェクト: gl-works/ringpop-go
// TestErrorHandler tests that the errorHandler logs the correct error message.
func (s *HandlerTestSuite) TestErrorHandler() {
	logger := &mocks.Logger{}

	// Make sure random log messages can be sent to this logger while it
	// replaces the existing one.
	logger.On("WithField", mock.Anything).Return(logger)
	logger.On("WithFields", mock.Anything).Return(logger)
	for _, meth := range []string{"Debug", "Info", "Warn", "Error"} {
		// Debug(msg)
		logger.On(meth, mock.Anything)
		// Debugf(format, msg)
		logger.On(meth+"f", mock.Anything, mock.Anything)
	}

	errTest := errors.New("test error")
	logging.SetLogger(logger)

	s.testNode.node.errorHandler(s.ctx, errTest)
	logger.AssertCalled(s.T(), "WithFields", bark.Fields{
		"local": s.testNode.node.Address(),
		"error": errTest,
	})
	logger.AssertCalled(s.T(), "Info", []interface{}{"error occurred"})
}
コード例 #2
0
ファイル: options.go プロジェクト: gl-works/ringpop-go
// Logger is used to specify a bark-compatible logger that will be used for
// all Ringpop logging. If a logger is not provided, one will be created
// automatically.
func Logger(l log.Logger) Option {
	return func(r *Ringpop) error {
		logging.SetLogger(l)
		return nil
	}
}