/src/lib/log/logger.e

http://github.com/tybor/Liberty · Specman e · 144 lines · 99 code · 19 blank · 26 comment · 0 complexity · 70316e11da99a7c6de50e9f47c737c07 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class LOGGER
  5. --
  6. -- A simple logger.
  7. --
  8. create {LOG_INTERNAL_CONF}
  9. make
  10. feature {ANY}
  11. parent: LOGGER
  12. level: LOG_LEVEL
  13. tag: FIXED_STRING
  14. feature {ANY} -- Logging streams
  15. trace: OUTPUT_STREAM
  16. do
  17. Result := levels.trace.stream(Current)
  18. ensure
  19. Result /= Void
  20. end
  21. info: OUTPUT_STREAM
  22. do
  23. Result := levels.info.stream(Current)
  24. ensure
  25. Result /= Void
  26. end
  27. warning: OUTPUT_STREAM
  28. do
  29. Result := levels.warning.stream(Current)
  30. ensure
  31. Result /= Void
  32. end
  33. error: OUTPUT_STREAM
  34. do
  35. Result := levels.error.stream(Current)
  36. ensure
  37. Result /= Void
  38. end
  39. feature {ANY} -- Logging checks
  40. is_trace: BOOLEAN
  41. do
  42. Result := levels.trace.does_log(level)
  43. end
  44. is_info: BOOLEAN
  45. do
  46. Result := levels.info.does_log(level)
  47. end
  48. is_warning: BOOLEAN
  49. do
  50. Result := levels.warning.does_log(level)
  51. end
  52. is_error: BOOLEAN
  53. do
  54. Result := levels.error.does_log(level)
  55. end
  56. feature {ANY} -- Log level
  57. set_level (a_level: like level)
  58. require
  59. a_level /= Void
  60. do
  61. level := a_level
  62. ensure
  63. level = a_level
  64. end
  65. feature {LOG_INTERNAL_CONF} -- Parent logger
  66. set_parent (a_parent: like parent)
  67. require
  68. a_parent /= Void
  69. do
  70. parent := a_parent
  71. set_level(a_parent.level)
  72. ensure
  73. parent = a_parent
  74. end
  75. feature {LOG_INTERNAL_CONF, LOG_LEVEL} -- Log output, internal usage only
  76. output: LOG_OUTPUT
  77. feature {LOGGING}
  78. is_valid: BOOLEAN
  79. local
  80. conf: LOG_CONFIGURATION
  81. do
  82. Result := generation_id = conf.generation_id
  83. end
  84. feature {}
  85. make (a_output: LOG_OUTPUT; a_tag: like tag; a_id: like generation_id)
  86. require
  87. a_output /= Void
  88. do
  89. output := a_output
  90. tag := a_tag
  91. generation_id := a_id
  92. set_level(levels.trace)
  93. ensure
  94. output = a_output
  95. tag = a_tag
  96. generation_id = a_id
  97. is_valid
  98. end
  99. levels: LOG_LEVELS
  100. feature {LOG_INTERNAL_CONF}
  101. generation_id: INTEGER
  102. invariant
  103. tag /= Void
  104. level /= Void
  105. end -- class LOGGER
  106. --
  107. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  108. --
  109. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  110. -- of this software and associated documentation files (the "Software"), to deal
  111. -- in the Software without restriction, including without limitation the rights
  112. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  113. -- copies of the Software, and to permit persons to whom the Software is
  114. -- furnished to do so, subject to the following conditions:
  115. --
  116. -- The above copyright notice and this permission notice shall be included in
  117. -- all copies or substantial portions of the Software.
  118. --
  119. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  120. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  121. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  122. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  123. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  124. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  125. -- THE SOFTWARE.