PageRenderTime 20ms CodeModel.GetById 17ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 1ms

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