/src/lib/log/log_level.e

http://github.com/tybor/Liberty · Specman e · 84 lines · 53 code · 8 blank · 23 comment · 3 complexity · 2667c6876618fcd039eb61884bbb0fa5 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class LOG_LEVEL
  5. create {LOG_LEVELS}
  6. make
  7. feature {ANY}
  8. level: INTEGER
  9. tag: FIXED_STRING
  10. feature {LOGGER}
  11. stream (a_logger: LOGGER): OUTPUT_STREAM
  12. require
  13. a_logger /= Void
  14. local
  15. parent_stream: OUTPUT_STREAM
  16. do
  17. if does_log(a_logger.level) then
  18. a_logger.output.set_forward(bottomless_pit)
  19. if a_logger.parent /= Void then
  20. parent_stream := stream(a_logger.parent)
  21. if parent_stream /= a_logger.output then
  22. a_logger.output.set_forward(parent_stream)
  23. end
  24. end
  25. a_logger.output.set(tag, a_logger.tag)
  26. Result := a_logger.output
  27. else
  28. Result := bottomless_pit
  29. end
  30. ensure
  31. Result /= Void
  32. end
  33. does_log (a_level: like Current): BOOLEAN
  34. require
  35. a_level /= Void
  36. do
  37. Result := a_level.level >= level
  38. end
  39. feature {}
  40. make (a_level: like level; a_tag: like tag)
  41. require
  42. a_tag /= Void
  43. do
  44. level := a_level
  45. tag := a_tag
  46. ensure
  47. level = a_level
  48. tag = a_tag
  49. end
  50. bottomless_pit: OUTPUT_STREAM
  51. once
  52. create {NULL_OUTPUT_STREAM} Result
  53. end
  54. invariant
  55. tag /= Void
  56. end -- class LOG_LEVEL
  57. --
  58. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  59. --
  60. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  61. -- of this software and associated documentation files (the "Software"), to deal
  62. -- in the Software without restriction, including without limitation the rights
  63. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  64. -- copies of the Software, and to permit persons to whom the Software is
  65. -- furnished to do so, subject to the following conditions:
  66. --
  67. -- The above copyright notice and this permission notice shall be included in
  68. -- all copies or substantial portions of the Software.
  69. --
  70. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  71. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  72. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  73. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  74. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  75. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  76. -- THE SOFTWARE.