http urls monitor.

default_notepad.go 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright © 2016 Steve Francia <spf@spf13.com>.
  2. //
  3. // Use of this source code is governed by an MIT-style
  4. // license that can be found in the LICENSE file.
  5. package jwalterweatherman
  6. import (
  7. "io"
  8. "io/ioutil"
  9. "log"
  10. "os"
  11. )
  12. var (
  13. TRACE *log.Logger
  14. DEBUG *log.Logger
  15. INFO *log.Logger
  16. WARN *log.Logger
  17. ERROR *log.Logger
  18. CRITICAL *log.Logger
  19. FATAL *log.Logger
  20. LOG *log.Logger
  21. FEEDBACK *Feedback
  22. defaultNotepad *Notepad
  23. )
  24. func reloadDefaultNotepad() {
  25. TRACE = defaultNotepad.TRACE
  26. DEBUG = defaultNotepad.DEBUG
  27. INFO = defaultNotepad.INFO
  28. WARN = defaultNotepad.WARN
  29. ERROR = defaultNotepad.ERROR
  30. CRITICAL = defaultNotepad.CRITICAL
  31. FATAL = defaultNotepad.FATAL
  32. LOG = defaultNotepad.LOG
  33. FEEDBACK = defaultNotepad.FEEDBACK
  34. }
  35. func init() {
  36. defaultNotepad = NewNotepad(LevelError, LevelWarn, os.Stdout, ioutil.Discard, "", log.Ldate|log.Ltime)
  37. reloadDefaultNotepad()
  38. }
  39. // SetLogThreshold set the log threshold for the default notepad. Trace by default.
  40. func SetLogThreshold(threshold Threshold) {
  41. defaultNotepad.SetLogThreshold(threshold)
  42. reloadDefaultNotepad()
  43. }
  44. // SetLogOutput set the log output for the default notepad. Discarded by default.
  45. func SetLogOutput(handle io.Writer) {
  46. defaultNotepad.SetLogOutput(handle)
  47. reloadDefaultNotepad()
  48. }
  49. // SetStdoutThreshold set the standard output threshold for the default notepad.
  50. // Info by default.
  51. func SetStdoutThreshold(threshold Threshold) {
  52. defaultNotepad.SetStdoutThreshold(threshold)
  53. reloadDefaultNotepad()
  54. }
  55. // SetPrefix set the prefix for the default logger. Empty by default.
  56. func SetPrefix(prefix string) {
  57. defaultNotepad.SetPrefix(prefix)
  58. reloadDefaultNotepad()
  59. }
  60. // SetFlags set the flags for the default logger. "log.Ldate | log.Ltime" by default.
  61. func SetFlags(flags int) {
  62. defaultNotepad.SetFlags(flags)
  63. reloadDefaultNotepad()
  64. }
  65. // Level returns the current global log threshold.
  66. func LogThreshold() Threshold {
  67. return defaultNotepad.logThreshold
  68. }
  69. // Level returns the current global output threshold.
  70. func StdoutThreshold() Threshold {
  71. return defaultNotepad.stdoutThreshold
  72. }
  73. // GetStdoutThreshold returns the defined Treshold for the log logger.
  74. func GetLogThreshold() Threshold {
  75. return defaultNotepad.GetLogThreshold()
  76. }
  77. // GetStdoutThreshold returns the Treshold for the stdout logger.
  78. func GetStdoutThreshold() Threshold {
  79. return defaultNotepad.GetStdoutThreshold()
  80. }
  81. // LogCountForLevel returns the number of log invocations for a given threshold.
  82. func LogCountForLevel(l Threshold) uint64 {
  83. return defaultNotepad.LogCountForLevel(l)
  84. }
  85. // LogCountForLevelsGreaterThanorEqualTo returns the number of log invocations
  86. // greater than or equal to a given threshold.
  87. func LogCountForLevelsGreaterThanorEqualTo(threshold Threshold) uint64 {
  88. return defaultNotepad.LogCountForLevelsGreaterThanorEqualTo(threshold)
  89. }
  90. // ResetLogCounters resets the invocation counters for all levels.
  91. func ResetLogCounters() {
  92. defaultNotepad.ResetLogCounters()
  93. }