PageRenderTime 319ms CodeModel.GetById 317ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/library/logger/logger.e

http://github.com/jocelyn/EiffelWebReloaded
Specman e | 129 lines | 105 code | 14 blank | 10 comment | 7 complexity | 7cfcd689b2e14f0a8cefe1b04ea6270b MD5 | raw file
  1note
  2	description : "Objects that represent an log tracer"
  3	legal: "See notice at end of class."
  4	status: "See notice at end of class."
  5	date: "$Date$"
  6	revision: "$Revision$"
  7
  8deferred class
  9	LOGGER
 10
 11feature -- Access
 12
 13	application_name: detachable STRING
 14			-- Optional application name.
 15			-- Mainly used when log is shared between several application.
 16
 17	logging_level: INTEGER
 18			-- Logging level
 19			-- log will be executed only when the parameter `a_level' is equal or bigger than `logging_level'
 20			--| When it is negative the logging is disabled
 21
 22feature -- Element change
 23
 24	set_application_name (n: like application_name)
 25			-- Set `application_name' to 'n'
 26		do
 27			application_name := n
 28		end
 29
 30	set_logging_level (lev: like logging_level)
 31			-- Set `logging_level' to `lev'
 32		do
 33			logging_level := lev
 34		end
 35
 36feature {NONE} -- Logging
 37
 38	execute_log (m: STRING)
 39			-- Execute the logging of `m'
 40		deferred
 41		end
 42
 43feature -- Logging
 44
 45	log (a_level: INTEGER; m: STRING)
 46		do
 47			if logging_level >= 0 and then a_level >= logging_level then
 48				if attached application_name as n then
 49					execute_log ("[" + n + "]" + m)
 50				else
 51					execute_log (m)
 52				end
 53			end
 54		end
 55
 56	logf (a_level: INTEGER; fmt: STRING; args: ARRAY [detachable ANY])
 57			-- Log message formatted with arguments
 58			-- replace $1 with first value from args ... and so on
 59		require
 60			a_level_positive: a_level >= 0
 61		local
 62			s,num: STRING
 63			i,j,n,low: INTEGER
 64			c: CHARACTER
 65		do
 66			if args.count > 0 then
 67				from
 68					i := 1
 69					n := fmt.count
 70					create s.make (n)
 71					create num.make_empty
 72					low := args.lower
 73				until
 74					i > n
 75				loop
 76					c := fmt[i]
 77					inspect c
 78					when '$' then
 79						from
 80							j := 1
 81						until
 82							i+j > n or else not fmt[i+j].is_digit
 83						loop
 84							num.extend (fmt[i+j])
 85							i := i + 1
 86						end
 87						if num.count > 0 then
 88							i := i + j - 1
 89							j := num.to_integer - low + 1
 90							if args.valid_index (j) then
 91								if attached args[j] as v then
 92									s.append (v.out)
 93								else
 94									s.append ("Void")
 95								end
 96							else
 97								s.extend (c)
 98								s.append (num)
 99							end
100							num.wipe_out
101						else
102							s.extend (c)
103						end
104					else
105						s.extend (c)
106					end
107					i := i + 1
108				end
109			else
110				s := fmt
111			end
112			log (a_level, s)
113		end
114
115	close
116		do
117		end
118
119note
120	copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
121	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
122	source: "[
123			Eiffel Software
124			5949 Hollister Ave., Goleta, CA 93117 USA
125			Telephone 805-685-1006, Fax 805-685-6869
126			Website http://www.eiffel.com
127			Customer support http://support.eiffel.com
128		]"
129end