indexing description: "[ Please see EM_LOGGING for more information ]" date: "$Date$" revision: "$Revision$" class EM_LOGGER create make, make_with_file feature -- Creation make is -- creation procedure do set_output_type (true) set_output_newline (true) time_format := "[0]hh:[0]mi:[0]ss.ff3" end make_with_file (a_file_name: STRING) is -- creates a file, in which output may be generated require a_file_name_exist: a_file_name /= void a_file_name_not_empty: not a_file_name.is_empty do file_name := a_file_name ensure file_name_set: file_name = a_file_name end feature -- Element Change set_output_type (v: BOOLEAN) is -- true, if the type of the output should be displayed -- default is true do output_type := v ensure output_type = v end set_output_newline (v: BOOLEAN) is -- true, if a newline should be displayed at the end of the line -- default is true do output_newline := v ensure output_newline = v end set_output_time (v: BOOLEAN) is -- true, if the time should be displayed do output_time := v ensure output_time = v end set_output_warning_to_console (v: BOOLEAN) is -- true, if warnings should be displayed in the console do warning_output_console := v ensure warning_output_console = v end set_output_error_to_console (v: BOOLEAN) is -- true, if errors should be displayed in the console do error_output_console := v ensure error_output_console = v end set_output_debug_to_console (v: BOOLEAN) is -- true, if debugging information should be displayed in the console do debug_output_console := v ensure debug_output_console = v end set_output_log_to_console (v: BOOLEAN) is -- true, if the logs should be displayed in the console do log_output_console := v ensure log_output_console = v end set_output_warning_to_file (v: BOOLEAN) is -- true, if warnings should be displayed in the file require file_name_exist: file_name /= void file_must_be_set: not file_name.is_empty do warning_output_file := v ensure warning_output_file = v end set_output_error_to_file (v: BOOLEAN) is -- true, if errors should be displayed in the file require file_name_exist: file_name /= void file_must_be_set: not file_name.is_empty do error_output_file := v ensure error_output_file = v end set_output_debug_to_file (v: BOOLEAN) is -- true, if debugging information should be displayed in the file require file_name_exist: file_name /= void file_must_be_set: not file_name.is_empty do debug_output_file := v ensure debug_output_file = v end set_output_log_to_file (v: BOOLEAN) is -- true, if the logs should be displayed in the file require file_name_exist: file_name /= void file_must_be_set: not file_name.is_empty do log_output_file := v ensure log_output_file = v end set_time_format (s: STRING) is -- sets the time format do time_format := s ensure time_format = s end set_file (a_file_name: STRING) is -- sets the file reference require a_file_name_exist: a_file_name /= void a_file_name_not_empty: not a_file_name.is_empty do file_name := a_file_name ensure file_name_set: file_name = a_file_name end feature -- Removal delete_file is -- deletes/resets the file, if a filename is known local file: KL_TEXT_OUTPUT_FILE do if file_name /= void and not file_name.is_empty then create file.make (file_name) if file.exists then file.delete end end end feature -- Output write_warning (s: STRING) is -- logs the string s, if some log_output is enabled require s_not_void: s /= Void local msg: STRING do if warning_output_file or warning_output_console then -- generate string msg := "" msg := append_time (msg) if output_type then msg := msg + "warning: " end msg := msg + s if output_newline then msg := msg + "%N" end -- output the generated string to the console if warning_output_console then io.put_string (msg) end -- output the generated string to the appropriate file if warning_output_file then append_to_file (msg) end end end write_error (s: STRING) is -- logs the string s, if some log_output is enabled require s_not_void: s /= Void local msg: STRING do if error_output_file or error_output_console then -- generate string msg := "" msg := append_time (msg) if output_type then msg := msg + "error: " end msg := msg + s if output_newline then msg := msg + "%N" end -- output the generated string to the console if error_output_console then io.put_string (msg) end -- output the generated string to the appropriate file if error_output_file then append_to_file (msg) end end end write_debug (s: STRING) is -- logs the string s, if some log_output is enabled require s_not_void: s /= Void local msg: STRING do if debug_output_file or debug_output_console then -- generate string msg := "" msg := append_time (msg) if output_type then msg := msg + "debug: " end msg := msg + s if output_newline then msg := msg + "%N" end -- output the generated string to the console if debug_output_console then io.put_string (msg) end -- output the generated string to the appropriate file if debug_output_file then append_to_file (msg) end end end write_log (s: STRING) is -- logs the string s, if some log_output is enabled require s_not_void: s /= Void local msg: STRING do if log_output_file or log_output_console then -- generate string msg := "" msg := append_time (msg) if output_type then msg := msg + "log: " end msg := msg + s if output_newline then msg := msg + "%N" end -- output the generated string to the console if log_output_console then io.put_string (msg) end -- output the generated string to the appropriate file if log_output_file then append_to_file (msg) end end end feature -- Queries file_name: STRING -- the file, in which we want to write the logs warning_output_console: BOOLEAN -- if true, warning output will be done in the console error_output_console: BOOLEAN -- if true, error output will be done in the console debug_output_console: BOOLEAN -- if true, debug output will be done in the console log_output_console: BOOLEAN -- if true, log output will be done in the console warning_output_file: BOOLEAN -- if true, warning output will be done in a file error_output_file: BOOLEAN -- if true, error output will be done in a file debug_output_file: BOOLEAN -- if true, debug output will be done in a file log_output_file: BOOLEAN -- if true, log output will be done in a file output_type: BOOLEAN -- if true, the type will be displayed aswell, for example -- "ERROR: "+somestring+newline output_newline: BOOLEAN -- if true, a newline will be displayed output_time: BOOLEAN -- if true, the time is displayed at the beginning of each message time_format: STRING -- the format of the time string feature {NONE} -- Implementation append_time (s: STRING): STRING is -- appends the time to a string local time: TIME do Result := "" if output_time then create time.make_now Result := s + time.formatted_out (time_format) + " - " end end append_to_file (s: STRING) is -- appends the string s to the appropriate file require file_name_set: file_name /= void file_name_not_empty: not file_name.is_empty local file: KL_TEXT_OUTPUT_FILE do create file.make (file_name) file.open_append check file.is_open_write end if file.is_open_write then file.put_string (s) file.close end check file.is_closed end end end