Class: LogObject
- Inherits:
-
Object
- Object
- LogObject
- Defined in:
- lib/opensecret/plugins.io/logs/log.object.rb
Overview
– – Log common objects such as – – - files – - maps – –
Class Method Summary collapse
-
.file(file_path, file_context) ⇒ Object
– – Log the file whose full path is given in the 1st parameter.
-
.map(the_map) ⇒ Object
– – Log map with a key-value pair on each line.
Class Method Details
.file(file_path, file_context) ⇒ Object
– – Log the file whose full path is given in the 1st parameter. – The string context is included in the logs which should explain – the whys and wherefores of the file. – – An exception is thrown if the file is not found. –
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/opensecret/plugins.io/logs/log.object.rb', line 19 def self.file file_path, file_context Throw.if_not_exists file_path log.debug(ere) { "# -- ------------------------------------------------------------------------ #" } log.debug(ere) { "# -- ------------------------------------------------------------------------ #" } log.debug(ere) { "# -- The File Path to Log => #{file_path}" } hr_file_size = PrettyPrint.byte_size( File.size(file_path) ) dotless_extension = File.extname( file_path )[1..-1] parent_dir_name = File.basename( File.dirname( file_path ) ) file_name = File.basename file_path is_zip = dotless_extension.eql? "zip" log.debug(ere) { "# -- ------------------------------------------------------------------------ #" } log.debug(ere) { "# -- File Name => #{file_name}" } log.debug(ere) { "# -- File Size => #{hr_file_size}" } log.debug(ere) { "# -- File Type => #{file_context}" } log.debug(ere) { "# -- In Folder => #{parent_dir_name}" } log.debug(ere) { "# -- ------------------------------------------------------------------------ #" } log.debug(ere) { "File #{file_name} is a zip (binary) file." } if is_zip return if is_zip File.open( file_path, "r") do | file_obj | line_no = 1 file_obj.each_line do | file_line | line_num = sprintf '%03d', line_no clean_line = file_line.chomp.strip log.debug(ere) { "# -- [#{line_num}] - #{clean_line}" } line_no += 1 end end log.debug(ere) { "# -- ------------------------------------------------------------------------ #" } log.debug(ere) { "# -- [#{file_context}] End of File [ #{File.basename(file_path)} ]" } log.debug(ere) { "# -- ------------------------------------------------------------------------ #" } end |
.map(the_map) ⇒ Object
– – Log map with a key-value pair on each line. – – Parameter – the_map : the map to log – – Dependencies and Assumptions – the map has been instantiated (not nil) –
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/opensecret/plugins.io/logs/log.object.rb', line 69 def self.map the_map return if the_map.nil? log.debug(ere) { "# --- ----------------------------------------------" } log.debug(ere) { "# --- Map has [#{the_map.length}] key/value pairs." } log.debug(ere) { "# --- ----------------------------------------------" } the_map.each do |the_key, the_value| padded_key = sprintf '%-33s', the_key log.debug(ere) { "# --- #{padded_key} => #{the_value}" } end log.debug(ere) { "# --- ----------------------------------------------" } end |