PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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