PageRenderTime 27ms CodeModel.GetById 20ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

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