Beispiel #1
0
func main() {
	// Configure logger
	logger := log15.New()
	logger.SetHandler(log15.StreamHandler(os.Stderr, log15.LogfmtFormat()))

	// Create service
	service := goa.New("goa Swagger service")
	service.WithLogger(goalog15.New(logger))

	// Setup middleware
	service.Use(middleware.RequestID())
	service.Use(middleware.LogRequest(true))
	service.Use(middleware.ErrorHandler(service, true))
	service.Use(middleware.Recover())

	// Mount "spec" controller
	c := NewSpecController(service)
	app.MountSpecController(service, c)

	// Mount "ae" controller
	h := NewAeController(service)
	app.MountAeController(service, h)

	// Start service, listen on port 8080
	if err := service.ListenAndServe(":8080"); err != nil {
		service.LogError(err.Error())
	}

	logger.Info("Exiting...")
}
Beispiel #2
0
type TestHandler struct {
	records []*log15.Record
}

func (h *TestHandler) Log(r *log15.Record) error {
	h.records = append(h.records, r)
	return nil
}

var _ = Describe("New", func() {
	var logger log15.Logger
	var adapter goa.LogAdapter
	var handler *TestHandler

	BeforeEach(func() {
		logger = log15.New()
		handler = new(TestHandler)
		logger.SetHandler(handler)
		adapter = goalog15.New(logger)
	})

	It("creates an adapter that logs", func() {
		msg := "msg"
		adapter.Info(msg)
		Ω(handler.records).Should(HaveLen(1))
		Ω(handler.records[0].Msg).Should(ContainSubstring(msg))
	})

	Context("Logger", func() {
		var ctx context.Context