本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.8KB

  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. // SetStdoutOutput set the stdout output for the default notepad. Default is stdout.
  56. func SetStdoutOutput(handle io.Writer) {
  57. defaultNotepad.outHandle = handle
  58. defaultNotepad.init()
  59. reloadDefaultNotepad()
  60. }
  61. // SetPrefix set the prefix for the default logger. Empty by default.
  62. func SetPrefix(prefix string) {
  63. defaultNotepad.SetPrefix(prefix)
  64. reloadDefaultNotepad()
  65. }
  66. // SetFlags set the flags for the default logger. "log.Ldate | log.Ltime" by default.
  67. func SetFlags(flags int) {
  68. defaultNotepad.SetFlags(flags)
  69. reloadDefaultNotepad()
  70. }
  71. // SetLogListeners configures the default logger with one or more log listeners.
  72. func SetLogListeners(l ...LogListener) {
  73. defaultNotepad.logListeners = l
  74. defaultNotepad.init()
  75. reloadDefaultNotepad()
  76. }
  77. // Level returns the current global log threshold.
  78. func LogThreshold() Threshold {
  79. return defaultNotepad.logThreshold
  80. }
  81. // Level returns the current global output threshold.
  82. func StdoutThreshold() Threshold {
  83. return defaultNotepad.stdoutThreshold
  84. }
  85. // GetStdoutThreshold returns the defined Treshold for the log logger.
  86. func GetLogThreshold() Threshold {
  87. return defaultNotepad.GetLogThreshold()
  88. }
  89. // GetStdoutThreshold returns the Treshold for the stdout logger.
  90. func GetStdoutThreshold() Threshold {
  91. return defaultNotepad.GetStdoutThreshold()
  92. }
上海开阖软件有限公司 沪ICP备12045867号-1