/src/lib/log/conf/log_file_options.e

http://github.com/tybor/Liberty · Specman e · 130 lines · 88 code · 14 blank · 28 comment · 4 complexity · 8ca85c05732975d0a0bb7b2a680f37e6 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_FILE_OPTIONS
  5. create {LOG_INTERNAL_CONF}
  6. file, console
  7. feature {LOG_INTERNAL_CONF}
  8. retriever: FUNCTION[TUPLE, OUTPUT_STREAM]
  9. do
  10. Result := agent retrieve
  11. end
  12. rotated (condition: PREDICATE[TUPLE[FILE_STREAM]]; retention: INTEGER_64; on_error: PROCEDURE[TUPLE[STRING]])
  13. require
  14. condition /= Void
  15. do
  16. if file_path = Void then
  17. on_error.call([output_name + ": 'rotated' not allowed on console"])
  18. elseif option_rotated then
  19. on_error.call([output_name + ": only one 'rotated' statement allowed"])
  20. else
  21. create {LOG_FILE_ROTATED} option.make(option, condition, retention)
  22. option_rotated := True
  23. end
  24. end
  25. zipped (command: FIXED_STRING; on_error: PROCEDURE[TUPLE[STRING]])
  26. require
  27. command /= Void
  28. do
  29. if file_path = Void then
  30. on_error.call([output_name + ": 'zipped' not allowed on console"])
  31. elseif option_zipped then
  32. on_error.call([output_name + ": only one 'zipped' statement allowed"])
  33. elseif not option_rotated then
  34. on_error.call([output_name + ": the 'zipped' statement must follow a 'rotated' statement"])
  35. else
  36. create {LOG_FILE_ZIPPED} option.make(option, command)
  37. option_zipped := True
  38. end
  39. end
  40. is_connected: BOOLEAN
  41. do
  42. Result := stream.is_connected
  43. end
  44. feature {}
  45. file (a_output_name: like output_name; a_file_path: like file_path)
  46. require
  47. a_output_name /= Void
  48. a_file_path /= Void
  49. do
  50. output_name := a_output_name
  51. file_path := a_file_path
  52. create {TEXT_FILE_WRITE} stream.connect_for_appending_to(a_file_path)
  53. do_at_exit(agent do if stream.is_connected then stream.disconnect end end)
  54. create {LOG_FILE_PASS_THROUGH} option.make
  55. ensure
  56. output_name = a_output_name
  57. file_path = a_file_path
  58. --stream.is_connected implies stream.path = a_file_path
  59. end
  60. console (a_output_name: like output_name)
  61. require
  62. a_output_name /= Void
  63. do
  64. output_name := a_output_name
  65. stream := std_output
  66. create {LOG_FILE_PASS_THROUGH} option.make
  67. ensure
  68. output_name = a_output_name
  69. file_path = Void
  70. stream = std_output
  71. end
  72. retrieve: OUTPUT_STREAM
  73. local
  74. s: STREAM
  75. do
  76. -- the stream may not be connected at shutdown (last GC collect)
  77. if stream.is_connected then
  78. -- because FILE_STREAM and OUTPUT_STREAM are in parallel hierarchies
  79. -- (they don't inherit from each other)
  80. -- ... but we know the stream is always an output one, don't we :-)
  81. s := option.retrieve(stream)
  82. stream ::= s
  83. Result ::= s
  84. end
  85. end
  86. option_rotated: BOOLEAN
  87. option_zipped: BOOLEAN
  88. option: LOG_FILE_OPTION
  89. stream: OUTPUT_STREAM
  90. output_name: FIXED_STRING
  91. file_path: STRING
  92. invariant
  93. stream /= Void
  94. option /= Void
  95. output_name /= Void
  96. end -- class LOG_FILE_OPTIONS
  97. --
  98. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  99. --
  100. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  101. -- of this software and associated documentation files (the "Software"), to deal
  102. -- in the Software without restriction, including without limitation the rights
  103. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  104. -- copies of the Software, and to permit persons to whom the Software is
  105. -- furnished to do so, subject to the following conditions:
  106. --
  107. -- The above copyright notice and this permission notice shall be included in
  108. -- all copies or substantial portions of the Software.
  109. --
  110. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  111. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  112. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  113. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  114. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  115. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  116. -- THE SOFTWARE.