github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/writers/writer_print.go (about)

     1  // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
     2  
     3  package writers
     4  
     5  import (
     6  	"io"
     7  	"log"
     8  )
     9  
    10  type PrintWriter struct {
    11  	rawWriter io.Writer
    12  	tag       string
    13  }
    14  
    15  func NewPrintWriter(rawWriter io.Writer, tag string) io.Writer {
    16  	return &PrintWriter{
    17  		rawWriter: rawWriter,
    18  		tag:       tag,
    19  	}
    20  }
    21  
    22  func (this *PrintWriter) Write(p []byte) (n int, err error) {
    23  	n, err = this.rawWriter.Write(p)
    24  	if n > 0 {
    25  		log.Println("[" + this.tag + "]" + string(p[:n]))
    26  	}
    27  	return
    28  }