http urls monitor.

exported.go 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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.mu.Lock()
  20. defer std.mu.Unlock()
  21. std.Formatter = formatter
  22. }
  23. // SetLevel sets the standard logger level.
  24. func SetLevel(level Level) {
  25. std.mu.Lock()
  26. defer std.mu.Unlock()
  27. std.SetLevel(level)
  28. }
  29. // GetLevel returns the standard logger level.
  30. func GetLevel() Level {
  31. std.mu.Lock()
  32. defer std.mu.Unlock()
  33. return std.level()
  34. }
  35. // AddHook adds a hook to the standard logger hooks.
  36. func AddHook(hook Hook) {
  37. std.mu.Lock()
  38. defer std.mu.Unlock()
  39. std.Hooks.Add(hook)
  40. }
  41. // WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key.
  42. func WithError(err error) *Entry {
  43. return std.WithField(ErrorKey, err)
  44. }
  45. // WithField creates an entry from the standard logger and adds a field to
  46. // it. If you want multiple fields, use `WithFields`.
  47. //
  48. // Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
  49. // or Panic on the Entry it returns.
  50. func WithField(key string, value interface{}) *Entry {
  51. return std.WithField(key, value)
  52. }
  53. // WithFields creates an entry from the standard logger and adds multiple
  54. // fields to it. This is simply a helper for `WithField`, invoking it
  55. // once for each field.
  56. //
  57. // Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
  58. // or Panic on the Entry it returns.
  59. func WithFields(fields Fields) *Entry {
  60. return std.WithFields(fields)
  61. }
  62. // WithTime creats an entry from the standard logger and overrides the time of
  63. // logs generated with it.
  64. //
  65. // Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
  66. // or Panic on the Entry it returns.
  67. func WithTime(t time.Time) *Entry {
  68. return std.WithTime(t)
  69. }
  70. // Debug logs a message at level Debug on the standard logger.
  71. func Debug(args ...interface{}) {
  72. std.Debug(args...)
  73. }
  74. // Print logs a message at level Info on the standard logger.
  75. func Print(args ...interface{}) {
  76. std.Print(args...)
  77. }
  78. // Info logs a message at level Info on the standard logger.
  79. func Info(args ...interface{}) {
  80. std.Info(args...)
  81. }
  82. // Warn logs a message at level Warn on the standard logger.
  83. func Warn(args ...interface{}) {
  84. std.Warn(args...)
  85. }
  86. // Warning logs a message at level Warn on the standard logger.
  87. func Warning(args ...interface{}) {
  88. std.Warning(args...)
  89. }
  90. // Error logs a message at level Error on the standard logger.
  91. func Error(args ...interface{}) {
  92. std.Error(args...)
  93. }
  94. // Panic logs a message at level Panic on the standard logger.
  95. func Panic(args ...interface{}) {
  96. std.Panic(args...)
  97. }
  98. // Fatal logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
  99. func Fatal(args ...interface{}) {
  100. std.Fatal(args...)
  101. }
  102. // Debugf logs a message at level Debug on the standard logger.
  103. func Debugf(format string, args ...interface{}) {
  104. std.Debugf(format, args...)
  105. }
  106. // Printf logs a message at level Info on the standard logger.
  107. func Printf(format string, args ...interface{}) {
  108. std.Printf(format, args...)
  109. }
  110. // Infof logs a message at level Info on the standard logger.
  111. func Infof(format string, args ...interface{}) {
  112. std.Infof(format, args...)
  113. }
  114. // Warnf logs a message at level Warn on the standard logger.
  115. func Warnf(format string, args ...interface{}) {
  116. std.Warnf(format, args...)
  117. }
  118. // Warningf logs a message at level Warn on the standard logger.
  119. func Warningf(format string, args ...interface{}) {
  120. std.Warningf(format, args...)
  121. }
  122. // Errorf logs a message at level Error on the standard logger.
  123. func Errorf(format string, args ...interface{}) {
  124. std.Errorf(format, args...)
  125. }
  126. // Panicf logs a message at level Panic on the standard logger.
  127. func Panicf(format string, args ...interface{}) {
  128. std.Panicf(format, args...)
  129. }
  130. // Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
  131. func Fatalf(format string, args ...interface{}) {
  132. std.Fatalf(format, args...)
  133. }
  134. // Debugln logs a message at level Debug on the standard logger.
  135. func Debugln(args ...interface{}) {
  136. std.Debugln(args...)
  137. }
  138. // Println logs a message at level Info on the standard logger.
  139. func Println(args ...interface{}) {
  140. std.Println(args...)
  141. }
  142. // Infoln logs a message at level Info on the standard logger.
  143. func Infoln(args ...interface{}) {
  144. std.Infoln(args...)
  145. }
  146. // Warnln logs a message at level Warn on the standard logger.
  147. func Warnln(args ...interface{}) {
  148. std.Warnln(args...)
  149. }
  150. // Warningln logs a message at level Warn on the standard logger.
  151. func Warningln(args ...interface{}) {
  152. std.Warningln(args...)
  153. }
  154. // Errorln logs a message at level Error on the standard logger.
  155. func Errorln(args ...interface{}) {
  156. std.Errorln(args...)
  157. }
  158. // Panicln logs a message at level Panic on the standard logger.
  159. func Panicln(args ...interface{}) {
  160. std.Panicln(args...)
  161. }
  162. // Fatalln logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
  163. func Fatalln(args ...interface{}) {
  164. std.Fatalln(args...)
  165. }