github.com/oarkflow/log@v1.0.78/logger_std_log.go (about)

     1  package log
     2  
     3  import (
     4  	stdLog "log"
     5  )
     6  
     7  type stdLogWriter struct {
     8  	Logger
     9  }
    10  
    11  func (w *stdLogWriter) Write(p []byte) (int, error) {
    12  	if w.Logger.silent(w.Logger.Level) {
    13  		return 0, nil
    14  	}
    15  	e := w.Logger.header(w.Level)
    16  	if caller, full := w.Logger.Caller, false; caller != 0 {
    17  		if caller < 0 {
    18  			caller, full = -caller, true
    19  		}
    20  		var pc uintptr
    21  		e.caller(caller1(caller+2, &pc, 1, 1), pc, full)
    22  	}
    23  	e.Msg(b2s(p))
    24  	return len(p), nil
    25  }
    26  
    27  // Std wraps the Logger to provide *stdLog.Logger
    28  func (l *Logger) Std(prefix string, flag int) *stdLog.Logger {
    29  	return stdLog.New(&stdLogWriter{*l}, prefix, flag)
    30  }