go.undefinedlabs.com/scopeagent@v0.4.2/instrumentation/logging/logger_go11.go (about)

     1  // +build !go1.12
     2  
     3  package logging
     4  
     5  import (
     6  	"io"
     7  	stdlog "log"
     8  	"os"
     9  
    10  	"go.undefinedlabs.com/scopeagent/reflection"
    11  )
    12  
    13  // Gets the standard logger writer
    14  func getStdLoggerWriter() io.Writer {
    15  	return os.Stderr // There is no way to get the current writer for the standard logger, but the default one is os.Stderr
    16  }
    17  
    18  // Gets the writer of a custom logger
    19  func getLoggerWriter(logger *stdlog.Logger) io.Writer {
    20  	// There is not API in Go1.11 to get the current writer, accessing by reflection.
    21  	if ptr, err := reflection.GetFieldPointerOf(logger, "out"); err == nil {
    22  		return *(*io.Writer)(ptr)
    23  	}
    24  	return nil
    25  }