logger.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package sizer
  2. import (
  3. "log"
  4. "github.com/fatih/color"
  5. )
  6. // Debug is a global bool to toggle debugging messages.
  7. var Debug bool
  8. type console log.Logger
  9. func (l *console) SetFlags(i int) {
  10. log.SetFlags(i)
  11. }
  12. func (l *console) Print(v ...interface{}) {
  13. log.Print(v...)
  14. }
  15. func (l *console) Printf(format string, v ...interface{}) {
  16. log.Printf(format, v...)
  17. }
  18. func (l *console) Println(v ...interface{}) {
  19. log.Println(v...)
  20. }
  21. func (l *console) Fatal(v ...interface{}) {
  22. log.Fatal(v...)
  23. }
  24. func (l *console) Fatalf(format string, v ...interface{}) {
  25. log.Fatalf(format, v...)
  26. }
  27. func (l *console) Fatalln(v ...interface{}) {
  28. log.Fatalln(v...)
  29. }
  30. func (l *console) Debug(msg ...interface{}) {
  31. if Debug {
  32. l.Print(msg...)
  33. }
  34. }
  35. func (l *console) Debugf(format string, msg ...interface{}) {
  36. if Debug {
  37. l.Printf(format, msg...)
  38. }
  39. }
  40. func (l *console) Debugln(msg ...interface{}) {
  41. if Debug {
  42. l.Println(msg...)
  43. }
  44. }
  45. // Console is the logger object
  46. var Console console
  47. func init() {
  48. Console.SetFlags(0)
  49. }
  50. // Red is a function that, given a string, returns the string
  51. // in ANSI red foreground color.
  52. var Red = color.New(color.FgRed).SprintFunc()
  53. // Green is a function that, given a string, returns the string
  54. // in ANSI green foreground color.
  55. var Green = color.New(color.FgGreen).SprintFunc()
  56. // Cyan is a function that, given a string, returns the string
  57. // in ANSI cyan foreground color.
  58. var Cyan = color.New(color.FgCyan).SprintFunc()