ruspa.v0/sizer/logger.go

78 lines
1.4 KiB
Go
Raw Normal View History

2019-03-06 15:03:21 +01:00
package sizer
2019-05-16 20:55:59 +02:00
import (
"log"
"github.com/fatih/color"
)
2019-03-06 15:03:21 +01:00
// 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)
}
2019-05-16 20:55:59 +02:00
// 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()