exported.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. package logrus
  2. import (
  3. "io"
  4. "time"
  5. )
  6. var (
  7. // std is the name of the standard logger in stdlib `log`
  8. std = New()
  9. )
  10. func StandardLogger() *Logger {
  11. return std
  12. }
  13. // SetOutput sets the standard logger output.
  14. func SetOutput(out io.Writer) {
  15. std.SetOutput(out)
  16. }
  17. // SetFormatter sets the standard logger formatter.
  18. func SetFormatter(formatter Formatter) {
  19. std.SetFormatter(formatter)
  20. }
  21. // SetReportCaller sets whether the standard logger will include the calling
  22. // method as a field.
  23. func SetReportCaller(include bool) {
  24. std.SetReportCaller(include)
  25. }
  26. // SetLevel sets the standard logger level.
  27. func SetLevel(level Level) {
  28. std.SetLevel(level)
  29. }
  30. // GetLevel returns the standard logger level.
  31. func GetLevel() Level {
  32. return std.GetLevel()
  33. }
  34. // IsLevelEnabled checks if the log level of the standard logger is greater than the level param
  35. func IsLevelEnabled(level Level) bool {
  36. return std.IsLevelEnabled(level)
  37. }
  38. // AddHook adds a hook to the standard logger hooks.
  39. func AddHook(hook Hook) {
  40. std.AddHook(hook)
  41. }
  42. // WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key.
  43. func WithError(err error) *Entry {
  44. return std.WithField(ErrorKey, err)
  45. }
  46. // WithField creates an entry from the standard logger and adds a field to
  47. // it. If you want multiple fields, use `WithFields`.
  48. //
  49. // Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
  50. // or Panic on the Entry it returns.
  51. func WithField(key string, value interface{}) *Entry {
  52. return std.WithField(key, value)
  53. }
  54. // WithFields creates an entry from the standard logger and adds multiple
  55. // fields to it. This is simply a helper for `WithField`, invoking it
  56. // once for each field.
  57. //
  58. // Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
  59. // or Panic on the Entry it returns.
  60. func WithFields(fields Fields) *Entry {
  61. return std.WithFields(fields)
  62. }
  63. // WithTime creats an entry from the standard logger and overrides the time of
  64. // logs generated with it.
  65. //
  66. // Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
  67. // or Panic on the Entry it returns.
  68. func WithTime(t time.Time) *Entry {
  69. return std.WithTime(t)
  70. }
  71. // Trace logs a message at level Trace on the standard logger.
  72. func Trace(args ...interface{}) {
  73. std.Trace(args...)
  74. }
  75. // Debug logs a message at level Debug on the standard logger.
  76. func Debug(args ...interface{}) {
  77. std.Debug(args...)
  78. }
  79. // Print logs a message at level Info on the standard logger.
  80. func Print(args ...interface{}) {
  81. std.Print(args...)
  82. }
  83. // Info logs a message at level Info on the standard logger.
  84. func Info(args ...interface{}) {
  85. std.Info(args...)
  86. }
  87. // Warn logs a message at level Warn on the standard logger.
  88. func Warn(args ...interface{}) {
  89. std.Warn(args...)
  90. }
  91. // Warning logs a message at level Warn on the standard logger.
  92. func Warning(args ...interface{}) {
  93. std.Warning(args...)
  94. }
  95. // Error logs a message at level Error on the standard logger.
  96. func Error(args ...interface{}) {
  97. std.Error(args...)
  98. }
  99. // Panic logs a message at level Panic on the standard logger.
  100. func Panic(args ...interface{}) {
  101. std.Panic(args...)
  102. }
  103. // Fatal logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
  104. func Fatal(args ...interface{}) {
  105. std.Fatal(args...)
  106. }
  107. // Tracef logs a message at level Trace on the standard logger.
  108. func Tracef(format string, args ...interface{}) {
  109. std.Tracef(format, args...)
  110. }
  111. // Debugf logs a message at level Debug on the standard logger.
  112. func Debugf(format string, args ...interface{}) {
  113. std.Debugf(format, args...)
  114. }
  115. // Printf logs a message at level Info on the standard logger.
  116. func Printf(format string, args ...interface{}) {
  117. std.Printf(format, args...)
  118. }
  119. // Infof logs a message at level Info on the standard logger.
  120. func Infof(format string, args ...interface{}) {
  121. std.Infof(format, args...)
  122. }
  123. // Warnf logs a message at level Warn on the standard logger.
  124. func Warnf(format string, args ...interface{}) {
  125. std.Warnf(format, args...)
  126. }
  127. // Warningf logs a message at level Warn on the standard logger.
  128. func Warningf(format string, args ...interface{}) {
  129. std.Warningf(format, args...)
  130. }
  131. // Errorf logs a message at level Error on the standard logger.
  132. func Errorf(format string, args ...interface{}) {
  133. std.Errorf(format, args...)
  134. }
  135. // Panicf logs a message at level Panic on the standard logger.
  136. func Panicf(format string, args ...interface{}) {
  137. std.Panicf(format, args...)
  138. }
  139. // Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
  140. func Fatalf(format string, args ...interface{}) {
  141. std.Fatalf(format, args...)
  142. }
  143. // Traceln logs a message at level Trace on the standard logger.
  144. func Traceln(args ...interface{}) {
  145. std.Traceln(args...)
  146. }
  147. // Debugln logs a message at level Debug on the standard logger.
  148. func Debugln(args ...interface{}) {
  149. std.Debugln(args...)
  150. }
  151. // Println logs a message at level Info on the standard logger.
  152. func Println(args ...interface{}) {
  153. std.Println(args...)
  154. }
  155. // Infoln logs a message at level Info on the standard logger.
  156. func Infoln(args ...interface{}) {
  157. std.Infoln(args...)
  158. }
  159. // Warnln logs a message at level Warn on the standard logger.
  160. func Warnln(args ...interface{}) {
  161. std.Warnln(args...)
  162. }
  163. // Warningln logs a message at level Warn on the standard logger.
  164. func Warningln(args ...interface{}) {
  165. std.Warningln(args...)
  166. }
  167. // Errorln logs a message at level Error on the standard logger.
  168. func Errorln(args ...interface{}) {
  169. std.Errorln(args...)
  170. }
  171. // Panicln logs a message at level Panic on the standard logger.
  172. func Panicln(args ...interface{}) {
  173. std.Panicln(args...)
  174. }
  175. // Fatalln logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
  176. func Fatalln(args ...interface{}) {
  177. std.Fatalln(args...)
  178. }