level.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2013, Cong Ding. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // author: Cong Ding <dinggnu@gmail.com>
  16. package logging
  17. // Level is the type of level.
  18. type Level int32
  19. // Values of level
  20. const (
  21. CRITICAL Level = 50
  22. FATAL Level = CRITICAL
  23. ERROR Level = 40
  24. WARNING Level = 30
  25. WARN Level = WARNING
  26. INFO Level = 20
  27. DEBUG Level = 10
  28. NOTSET Level = 0
  29. )
  30. // The mapping from level to level name
  31. var levelNames = map[Level]string{
  32. CRITICAL: "CRITICAL",
  33. ERROR: "ERROR",
  34. WARNING: "WARNING",
  35. INFO: "INFO",
  36. DEBUG: "DEBUG",
  37. NOTSET: "NOTSET",
  38. }
  39. // The mapping from level name to level
  40. var levelValues = map[string]Level{
  41. "CRITICAL": CRITICAL,
  42. "ERROR": ERROR,
  43. "WARN": WARNING,
  44. "WARNING": WARNING,
  45. "INFO": INFO,
  46. "DEBUG": DEBUG,
  47. "NOTSET": NOTSET,
  48. }
  49. // String function casts level value to string
  50. func (level *Level) String() string {
  51. return levelNames[*level]
  52. }
  53. // GetLevelName lets users be able to get level name from level value.
  54. func GetLevelName(levelValue Level) string {
  55. return levelNames[levelValue]
  56. }
  57. // GetLevelValue lets users be able to get level value from level name.
  58. func GetLevelValue(levelName string) Level {
  59. return levelValues[levelName]
  60. }