scoped.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package logging
  2. import (
  3. "sync/atomic"
  4. )
  5. // LogLevel represents the level at which the logger will emit log messages
  6. type LogLevel int32
  7. // Set updates the LogLevel to the supplied value
  8. func (ll *LogLevel) Set(newLevel LogLevel) {
  9. atomic.StoreInt32((*int32)(ll), int32(newLevel))
  10. }
  11. // Get retrieves the current LogLevel value
  12. func (ll *LogLevel) Get() LogLevel {
  13. return LogLevel(atomic.LoadInt32((*int32)(ll)))
  14. }
  15. func (ll LogLevel) String() string {
  16. switch ll {
  17. case LogLevelDisabled:
  18. return "Disabled"
  19. case LogLevelError:
  20. return "Error"
  21. case LogLevelWarn:
  22. return "Warn"
  23. case LogLevelInfo:
  24. return "Info"
  25. case LogLevelDebug:
  26. return "Debug"
  27. case LogLevelTrace:
  28. return "Trace"
  29. default:
  30. return "UNKNOWN"
  31. }
  32. }
  33. const (
  34. // LogLevelDisabled completely disables logging of any events
  35. LogLevelDisabled LogLevel = iota
  36. // LogLevelError is for fatal errors which should be handled by user code,
  37. // but are logged to ensure that they are seen
  38. LogLevelError
  39. // LogLevelWarn is for logging abnormal, but non-fatal library operation
  40. LogLevelWarn
  41. // LogLevelInfo is for logging normal library operation (e.g. state transitions, etc.)
  42. LogLevelInfo
  43. // LogLevelDebug is for logging low-level library information (e.g. internal operations)
  44. LogLevelDebug
  45. // LogLevelTrace is for logging very low-level library information (e.g. network traces)
  46. LogLevelTrace
  47. )
  48. // LeveledLogger is the basic pion Logger interface
  49. type LeveledLogger interface {
  50. Trace(msg string)
  51. Tracef(format string, args ...interface{})
  52. Debug(msg string)
  53. Debugf(format string, args ...interface{})
  54. Info(msg string)
  55. Infof(format string, args ...interface{})
  56. Warn(msg string)
  57. Warnf(format string, args ...interface{})
  58. Error(msg string)
  59. Errorf(format string, args ...interface{})
  60. }
  61. // LoggerFactory is the basic pion LoggerFactory interface
  62. type LoggerFactory interface {
  63. NewLogger(scope string) LeveledLogger
  64. }