...

Source file src/edge-infra.dev/pkg/lib/fog/adapter.go

Documentation: edge-infra.dev/pkg/lib/fog

     1  package fog
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  
     7  	"github.com/go-logr/logr"
     8  )
     9  
    10  type infoWriter struct{ logr.Logger }
    11  
    12  func (w *infoWriter) Write(p []byte) (int, error) {
    13  	w.Info(string(p))
    14  	return len(p), nil
    15  }
    16  
    17  // InfoWriter creates a new io.Writer that writes output using the
    18  // logr.Logger's Info func
    19  func InfoWriter(l logr.Logger, name string) io.Writer {
    20  	return &infoWriter{l.WithName(name)}
    21  }
    22  
    23  type errorWriter struct {
    24  	logr.Logger
    25  	name string
    26  }
    27  
    28  func (w *errorWriter) Write(p []byte) (int, error) {
    29  	w.Error(fmt.Errorf("error occurred in %s", w.name), (string(p)))
    30  	return len(p), nil
    31  }
    32  
    33  // ErrorWriter creates a new io.Writer that writes output using the
    34  // logr.Logger's Error func, where the error indicates the name of the
    35  // writer that produced the error
    36  func ErrorWriter(l logr.Logger, name string) io.Writer {
    37  	return &errorWriter{
    38  		l.WithName(name), name,
    39  	}
    40  }
    41  

View as plain text