github.com/suzuken/ghq@v0.7.5-0.20160607064937-214ded0f64ec/utils/log.go (about)

     1  package utils
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/motemen/go-colorine"
     7  )
     8  
     9  var logger = &colorine.Logger{
    10  	colorine.Prefixes{
    11  		"git":      colorine.Verbose,
    12  		"hg":       colorine.Verbose,
    13  		"svn":      colorine.Verbose,
    14  		"darcs":    colorine.Verbose,
    15  		"skip":     colorine.Verbose,
    16  		"cd":       colorine.Verbose,
    17  		"resolved": colorine.Verbose,
    18  
    19  		"open":    colorine.Warn,
    20  		"exists":  colorine.Warn,
    21  		"warning": colorine.Warn,
    22  
    23  		"authorized": colorine.Notice,
    24  
    25  		"error": colorine.Error,
    26  
    27  		"": colorine.Info,
    28  	},
    29  }
    30  
    31  func Log(prefix, message string) {
    32  	logger.Log(prefix, message)
    33  }
    34  
    35  func ErrorIf(err error) bool {
    36  	if err != nil {
    37  		Log("error", err.Error())
    38  		return true
    39  	}
    40  
    41  	return false
    42  }
    43  
    44  func DieIf(err error) {
    45  	if err != nil {
    46  		Log("error", err.Error())
    47  		os.Exit(1)
    48  	}
    49  }
    50  
    51  func PanicIf(err error) {
    52  	if err != nil {
    53  		panic(err)
    54  	}
    55  }