github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/docgen/api/logging.go (about)

     1  package docgen
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  	golog "log"
     7  )
     8  
     9  var (
    10  	// Verbose enables verbose logging ([LOG] and [WARNING] messages)
    11  	Verbose bool
    12  
    13  	// Warning enables [WARNING] messages
    14  	Warning bool
    15  
    16  	// ExitStatus is what the recommended exit status should be
    17  	ExitStatus int
    18  )
    19  
    20  // SetLogger allows output messages to be redirected
    21  func SetLogger(w io.Writer) {
    22  	golog.SetOutput(w)
    23  }
    24  
    25  func log(v ...interface{}) {
    26  	if Verbose {
    27  		golog.Println(append([]interface{}{"[LOG]"}, v...)...)
    28  	}
    29  }
    30  
    31  func warning(file string, v ...interface{}) {
    32  	if Warning || Verbose {
    33  		/*ExitStatus++
    34  		if ExitStatus > 254 {
    35  			ExitStatus = 254
    36  		}*/
    37  
    38  		warning := fmt.Sprintf("[WARNING] %s:", file)
    39  		golog.Println(append([]interface{}{warning}, v...)...)
    40  	}
    41  }