package middleware

import (
	"github.com/ngaut/log"
	"github.com/pingcap/schrodinger/notifiermgr/event"
)

func logDriver(config *interface{}) Middleware {
	input := make(chan event.Event)
	output := make(chan event.Event)

	go func() {
		for rawEvent := range input {
			notification, ok := rawEvent.(Notification)
			if !ok {
				log.Errorf("input of log is not a Notification but %T", rawEvent)
			}

			log.Infof("FROM LOG SINK:\n %s", notification.Content)

			output <- rawEvent
		}
	}()

	return &RealMiddleware{
		input,
		output,
	}
}
