github.com/tooolbox/migrate/v4@v4.6.2-0.20200325001913-461b03b92064/internal/cli/log.go (about) 1 package cli 2 3 import ( 4 "fmt" 5 logpkg "log" 6 "os" 7 ) 8 9 // Log represents the logger 10 type Log struct { 11 verbose bool 12 } 13 14 // Printf prints out formatted string into a log 15 func (l *Log) Printf(format string, v ...interface{}) { 16 if l.verbose { 17 logpkg.Printf(format, v...) 18 } else { 19 fmt.Fprintf(os.Stderr, format, v...) 20 } 21 } 22 23 // Println prints out args into a log 24 func (l *Log) Println(args ...interface{}) { 25 if l.verbose { 26 logpkg.Println(args...) 27 } else { 28 fmt.Fprintln(os.Stderr, args...) 29 } 30 } 31 32 // Verbose shows if verbose print enabled 33 func (l *Log) Verbose() bool { 34 return l.verbose 35 } 36 37 func (l *Log) fatal(args ...interface{}) { 38 l.Println(args...) 39 os.Exit(1) 40 } 41 42 func (l *Log) fatalErr(err error) { 43 l.fatal("error:", err) 44 }