s_debug.go 643 B

12345678910111213141516171819202122232425262728293031323334
  1. package backends
  2. import (
  3. "fmt"
  4. "github.com/flashmob/go-guerrilla/mail"
  5. "strings"
  6. )
  7. func init() {
  8. streamers["debug"] = func() *StreamDecorator {
  9. return StreamDebug()
  10. }
  11. }
  12. func StreamDebug() *StreamDecorator {
  13. sd := &StreamDecorator{}
  14. sd.Decorate =
  15. func(sp StreamProcessor, a ...interface{}) StreamProcessor {
  16. sd.Open = func(e *mail.Envelope) error {
  17. return nil
  18. }
  19. return StreamProcessWith(func(p []byte) (int, error) {
  20. str := string(p)
  21. str = strings.Replace(str, "\n", "<LF>\n", -1)
  22. fmt.Println(str)
  23. Log().WithField("p", string(p)).Info("Debug stream")
  24. return sp.Write(p)
  25. })
  26. }
  27. return sd
  28. }