logger.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package log
  2. import (
  3. "log"
  4. "os"
  5. )
  6. const (
  7. calldepth = 3
  8. )
  9. var l Logger = &defaultLogger{log.New(os.Stdout, "", log.LstdFlags|log.Lshortfile)}
  10. type Logger interface {
  11. Debug(v ...interface{})
  12. Debugf(format string, v ...interface{})
  13. Info(v ...interface{})
  14. Infof(format string, v ...interface{})
  15. Warn(v ...interface{})
  16. Warnf(format string, v ...interface{})
  17. Error(v ...interface{})
  18. Errorf(format string, v ...interface{})
  19. Fatal(v ...interface{})
  20. Fatalf(format string, v ...interface{})
  21. Panic(v ...interface{})
  22. Panicf(format string, v ...interface{})
  23. }
  24. type Handler interface {
  25. Handle(v ...interface{})
  26. }
  27. func SetLogger(logger Logger) {
  28. l = logger
  29. }
  30. func SetDummyLogger() {
  31. l = &dummyLogger{}
  32. }
  33. func Debug(v ...interface{}) {
  34. l.Debug(v...)
  35. }
  36. func Debugf(format string, v ...interface{}) {
  37. l.Debugf(format, v...)
  38. }
  39. func Info(v ...interface{}) {
  40. l.Info(v...)
  41. }
  42. func Infof(format string, v ...interface{}) {
  43. l.Infof(format, v...)
  44. }
  45. func Warn(v ...interface{}) {
  46. l.Warn(v...)
  47. }
  48. func Warnf(format string, v ...interface{}) {
  49. l.Warnf(format, v...)
  50. }
  51. func Error(v ...interface{}) {
  52. l.Error(v...)
  53. }
  54. func Errorf(format string, v ...interface{}) {
  55. l.Errorf(format, v...)
  56. }
  57. func Fatal(v ...interface{}) {
  58. l.Fatal(v...)
  59. }
  60. func Fatalf(format string, v ...interface{}) {
  61. l.Fatalf(format, v...)
  62. }
  63. func Panic(v ...interface{}) {
  64. l.Panic(v...)
  65. }
  66. func Panicf(format string, v ...interface{}) {
  67. l.Panicf(format, v...)
  68. }
  69. func Handle(v ...interface{}) {
  70. if handle, ok := l.(Handler); ok {
  71. handle.Handle(v...)
  72. }
  73. }