fiberlog.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package log
  2. import (
  3. "context"
  4. "io"
  5. )
  6. // Fatal calls the default logger's Fatal method and then os.Exit(1).
  7. func Fatal(v ...interface{}) {
  8. logger.Fatal(v...)
  9. }
  10. // Error calls the default logger's Error method.
  11. func Error(v ...interface{}) {
  12. logger.Error(v...)
  13. }
  14. // Warn calls the default logger's Warn method.
  15. func Warn(v ...interface{}) {
  16. logger.Warn(v...)
  17. }
  18. // Info calls the default logger's Info method.
  19. func Info(v ...interface{}) {
  20. logger.Info(v...)
  21. }
  22. // Debug calls the default logger's Debug method.
  23. func Debug(v ...interface{}) {
  24. logger.Debug(v...)
  25. }
  26. // Trace calls the default logger's Trace method.
  27. func Trace(v ...interface{}) {
  28. logger.Trace(v...)
  29. }
  30. // Panic calls the default logger's Panic method.
  31. func Panic(v ...interface{}) {
  32. logger.Panic(v...)
  33. }
  34. // Fatalf calls the default logger's Fatalf method and then os.Exit(1).
  35. func Fatalf(format string, v ...interface{}) {
  36. logger.Fatalf(format, v...)
  37. }
  38. // Errorf calls the default logger's Errorf method.
  39. func Errorf(format string, v ...interface{}) {
  40. logger.Errorf(format, v...)
  41. }
  42. // Warnf calls the default logger's Warnf method.
  43. func Warnf(format string, v ...interface{}) {
  44. logger.Warnf(format, v...)
  45. }
  46. // Infof calls the default logger's Infof method.
  47. func Infof(format string, v ...interface{}) {
  48. logger.Infof(format, v...)
  49. }
  50. // Debugf calls the default logger's Debugf method.
  51. func Debugf(format string, v ...interface{}) {
  52. logger.Debugf(format, v...)
  53. }
  54. // Tracef calls the default logger's Tracef method.
  55. func Tracef(format string, v ...interface{}) {
  56. logger.Tracef(format, v...)
  57. }
  58. // Panicf calls the default logger's Tracef method.
  59. func Panicf(format string, v ...interface{}) {
  60. logger.Panicf(format, v...)
  61. }
  62. // Tracew logs a message with some additional context. The variadic key-value
  63. // pairs are treated as they are privateLog With.
  64. func Tracew(msg string, keysAndValues ...interface{}) {
  65. logger.Tracew(msg, keysAndValues...)
  66. }
  67. // Debugw logs a message with some additional context. The variadic key-value
  68. // pairs are treated as they are privateLog With.
  69. func Debugw(msg string, keysAndValues ...interface{}) {
  70. logger.Debugw(msg, keysAndValues...)
  71. }
  72. // Infow logs a message with some additional context. The variadic key-value
  73. // pairs are treated as they are privateLog With.
  74. func Infow(msg string, keysAndValues ...interface{}) {
  75. logger.Infow(msg, keysAndValues...)
  76. }
  77. // Warnw logs a message with some additional context. The variadic key-value
  78. // pairs are treated as they are privateLog With.
  79. func Warnw(msg string, keysAndValues ...interface{}) {
  80. logger.Warnw(msg, keysAndValues...)
  81. }
  82. // Errorw logs a message with some additional context. The variadic key-value
  83. // pairs are treated as they are privateLog With.
  84. func Errorw(msg string, keysAndValues ...interface{}) {
  85. logger.Errorw(msg, keysAndValues...)
  86. }
  87. // Fatalw logs a message with some additional context. The variadic key-value
  88. // pairs are treated as they are privateLog With.
  89. func Fatalw(msg string, keysAndValues ...interface{}) {
  90. logger.Fatalw(msg, keysAndValues...)
  91. }
  92. // Panicw logs a message with some additional context. The variadic key-value
  93. // pairs are treated as they are privateLog With.
  94. func Panicw(msg string, keysAndValues ...interface{}) {
  95. logger.Panicw(msg, keysAndValues...)
  96. }
  97. func WithContext(ctx context.Context) CommonLogger {
  98. return logger.WithContext(ctx)
  99. }
  100. // SetLogger sets the default logger and the system logger.
  101. // Note that this method is not concurrent-safe and must not be called
  102. // after the use of DefaultLogger and global functions privateLog this package.
  103. func SetLogger(v AllLogger) {
  104. logger = v
  105. }
  106. // SetOutput sets the output of default logger and system logger. By default, it is stderr.
  107. func SetOutput(w io.Writer) {
  108. logger.SetOutput(w)
  109. }
  110. // SetLevel sets the level of logs below which logs will not be output.
  111. // The default logger is LevelTrace.
  112. // Note that this method is not concurrent-safe.
  113. func SetLevel(lv Level) {
  114. logger.SetLevel(lv)
  115. }