ruspa.v0/sizer/logger.go
2019-05-16 20:55:59 +02:00

77 lines
1.4 KiB
Go

package sizer
import (
"log"
"github.com/fatih/color"
)
// Debug is a global bool to toggle debugging messages.
var Debug bool
type console log.Logger
func (l *console) SetFlags(i int) {
log.SetFlags(i)
}
func (l *console) Print(v ...interface{}) {
log.Print(v...)
}
func (l *console) Printf(format string, v ...interface{}) {
log.Printf(format, v...)
}
func (l *console) Println(v ...interface{}) {
log.Println(v...)
}
func (l *console) Fatal(v ...interface{}) {
log.Fatal(v...)
}
func (l *console) Fatalf(format string, v ...interface{}) {
log.Fatalf(format, v...)
}
func (l *console) Fatalln(v ...interface{}) {
log.Fatalln(v...)
}
func (l *console) Debug(msg ...interface{}) {
if Debug {
l.Print(msg...)
}
}
func (l *console) Debugf(format string, msg ...interface{}) {
if Debug {
l.Printf(format, msg...)
}
}
func (l *console) Debugln(msg ...interface{}) {
if Debug {
l.Println(msg...)
}
}
// Console is the logger object
var Console console
func init() {
Console.SetFlags(0)
}
// Red is a function that, given a string, returns the string
// in ANSI red foreground color.
var Red = color.New(color.FgRed).SprintFunc()
// Green is a function that, given a string, returns the string
// in ANSI green foreground color.
var Green = color.New(color.FgGreen).SprintFunc()
// Cyan is a function that, given a string, returns the string
// in ANSI cyan foreground color.
var Cyan = color.New(color.FgCyan).SprintFunc()