github.com/dhui/migrate@v3.4.0+incompatible/cli/log.go (about)

     1  package main
     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) fatalf(format string, v ...interface{}) {
    34  	l.Printf(format, v...)
    35  	os.Exit(1)
    36  }
    37  
    38  func (l *Log) fatal(args ...interface{}) {
    39  	l.Println(args...)
    40  	os.Exit(1)
    41  }
    42  
    43  func (l *Log) fatalErr(err error) {
    44  	l.fatal("error:", err)
    45  }