logger.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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()
  59. // Yellow is a function that, given a string, returns the string
  60. // in ANSI yellow foreground color.
  61. var Yellow = color.New(color.FgYellow).SprintFunc()
  62. // Gray is a function that, given a string, returns the string
  63. // in ANSI gray foreground color.
  64. var Gray = color.New(color.FgHiBlack).SprintFunc()