mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-04 10:03:42 +08:00 
			
		
		
		
	1.6.0 -------------------------- Fixes: * end of line cleanup * revert the entry concurrency bug fix whic leads to deadlock under some circumstances * update dependency on go-windows-terminal-sequences to fix a crash with go 1.14 Features: * add an option to the `TextFormatter` to completely disable fields quoting 1.5.0 -------------------------- Code quality: * add golangci linter run on travis Fixes: * add mutex for hooks concurrent access on `Entry` data * caller function field for go1.14 * fix build issue for gopherjs target Feature: * add an hooks/writer sub-package whose goal is to split output on different stream depending on the trace level * add a `DisableHTMLEscape` option in the `JSONFormatter` * add `ForceQuote` and `PadLevelText` options in the `TextFormatter` Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
		
			
				
	
	
		
			71 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package logrus
 | 
						|
 | 
						|
import (
 | 
						|
	"bufio"
 | 
						|
	"io"
 | 
						|
	"runtime"
 | 
						|
)
 | 
						|
 | 
						|
// Writer at INFO level. See WriterLevel for details.
 | 
						|
func (logger *Logger) Writer() *io.PipeWriter {
 | 
						|
	return logger.WriterLevel(InfoLevel)
 | 
						|
}
 | 
						|
 | 
						|
// WriterLevel returns an io.Writer that can be used to write arbitrary text to
 | 
						|
// the logger at the given log level. Each line written to the writer will be
 | 
						|
// printed in the usual way using formatters and hooks. The writer is part of an
 | 
						|
// io.Pipe and it is the callers responsibility to close the writer when done.
 | 
						|
// This can be used to override the standard library logger easily.
 | 
						|
func (logger *Logger) WriterLevel(level Level) *io.PipeWriter {
 | 
						|
	return NewEntry(logger).WriterLevel(level)
 | 
						|
}
 | 
						|
 | 
						|
func (entry *Entry) Writer() *io.PipeWriter {
 | 
						|
	return entry.WriterLevel(InfoLevel)
 | 
						|
}
 | 
						|
 | 
						|
func (entry *Entry) WriterLevel(level Level) *io.PipeWriter {
 | 
						|
	reader, writer := io.Pipe()
 | 
						|
 | 
						|
	var printFunc func(args ...interface{})
 | 
						|
 | 
						|
	switch level {
 | 
						|
	case TraceLevel:
 | 
						|
		printFunc = entry.Trace
 | 
						|
	case DebugLevel:
 | 
						|
		printFunc = entry.Debug
 | 
						|
	case InfoLevel:
 | 
						|
		printFunc = entry.Info
 | 
						|
	case WarnLevel:
 | 
						|
		printFunc = entry.Warn
 | 
						|
	case ErrorLevel:
 | 
						|
		printFunc = entry.Error
 | 
						|
	case FatalLevel:
 | 
						|
		printFunc = entry.Fatal
 | 
						|
	case PanicLevel:
 | 
						|
		printFunc = entry.Panic
 | 
						|
	default:
 | 
						|
		printFunc = entry.Print
 | 
						|
	}
 | 
						|
 | 
						|
	go entry.writerScanner(reader, printFunc)
 | 
						|
	runtime.SetFinalizer(writer, writerFinalizer)
 | 
						|
 | 
						|
	return writer
 | 
						|
}
 | 
						|
 | 
						|
func (entry *Entry) writerScanner(reader *io.PipeReader, printFunc func(args ...interface{})) {
 | 
						|
	scanner := bufio.NewScanner(reader)
 | 
						|
	for scanner.Scan() {
 | 
						|
		printFunc(scanner.Text())
 | 
						|
	}
 | 
						|
	if err := scanner.Err(); err != nil {
 | 
						|
		entry.Errorf("Error while reading from Writer: %s", err)
 | 
						|
	}
 | 
						|
	reader.Close()
 | 
						|
}
 | 
						|
 | 
						|
func writerFinalizer(writer *io.PipeWriter) {
 | 
						|
	writer.Close()
 | 
						|
}
 |