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. //
  17. package logging
  18. // Level is the type of level.
  19. type Level int32
  20. // Values of level
  21. const (
  22. CRITICAL Level = 50
  23. FATAL Level = CRITICAL
  24. ERROR Level = 40
  25. WARNING Level = 30
  26. WARN Level = WARNING
  27. INFO Level = 20
  28. DEBUG Level = 10
  29. NOTSET Level = 0
  30. )
  31. // The mapping from level to level name
  32. var levelNames = map[Level]string{
  33. CRITICAL: "CRITICAL",
  34. ERROR: "ERROR",
  35. WARNING: "WARNING",
  36. INFO: "INFO",
  37. DEBUG: "DEBUG",
  38. NOTSET: "NOTSET",
  39. }
  40. // The mapping from level name to level
  41. var levelValues = map[string]Level{
  42. "CRITICAL": CRITICAL,
  43. "ERROR": ERROR,
  44. "WARN": WARNING,
  45. "WARNING": WARNING,
  46. "INFO": INFO,
  47. "DEBUG": DEBUG,
  48. "NOTSET": NOTSET,
  49. }
  50. // String function casts level value to string
  51. func (level *Level) String() string {
  52. return levelNames[*level]
  53. }
  54. // GetLevelName lets users be able to get level name from level value.
  55. func GetLevelName(levelValue Level) string {
  56. return levelNames[levelValue]
  57. }
  58. // GetLevelValue lets users be able to get level value from level name.
  59. func GetLevelValue(levelName string) Level {
  60. return levelValues[levelName]
  61. }