github.com/TBD54566975/ftl@v0.219.0/internal/log/tee.go (about)

     1  package log
     2  
     3  import (
     4  	"errors"
     5  )
     6  
     7  // Tee returns a sink that writes to all of the given sinks.
     8  func Tee(sinks ...Sink) Sink {
     9  	return &tee{sinks: sinks}
    10  }
    11  
    12  type tee struct {
    13  	sinks []Sink
    14  }
    15  
    16  func (t *tee) Log(entry Entry) error {
    17  	var errs []error
    18  	for _, sink := range t.sinks {
    19  		if err := sink.Log(entry); err != nil {
    20  			errs = append(errs, err)
    21  		}
    22  	}
    23  	if len(errs) > 0 {
    24  		return errors.Join(errs...)
    25  	}
    26  	return nil
    27  }