github.com/bishtawi/migrate/v4@v4.8.11/internal/cli/log.go (about)

     1  package cli
     2  
     3  import (
     4  	"fmt"
     5  	logpkg "log"
     6  	"os"
     7  )
     8  
     9  type Log struct {
    10  	verbose bool
    11  }
    12  
    13  func (l *Log) Printf(format string, v ...interface{}) {
    14  	if l.verbose {
    15  		logpkg.Printf(format, v...)
    16  	} else {
    17  		fmt.Fprintf(os.Stderr, format, v...)
    18  	}
    19  }
    20  
    21  func (l *Log) Println(args ...interface{}) {
    22  	if l.verbose {
    23  		logpkg.Println(args...)
    24  	} else {
    25  		fmt.Fprintln(os.Stderr, args...)
    26  	}
    27  }
    28  
    29  func (l *Log) Verbose() bool {
    30  	return l.verbose
    31  }
    32  
    33  func (l *Log) fatal(args ...interface{}) {
    34  	l.Println(args...)
    35  	os.Exit(1)
    36  }
    37  
    38  func (l *Log) fatalErr(err error) {
    39  	l.fatal("error:", err)
    40  }