Module: WorkerTools::Recorder
- Defined in:
- lib/worker_tools/recorder.rb
Instance Method Summary collapse
- #add_info(message) ⇒ Object
- #add_log(message, level = :info) ⇒ Object
- #error_to_text(error, trace_lines = 20) ⇒ Object
- #format_info_message(message) ⇒ Object
- #format_log_message(message) ⇒ Object
- #info_error_trace_lines ⇒ Object
- #log_directory ⇒ Object
- #log_error_trace_lines ⇒ Object
- #log_file_name ⇒ Object
- #logger ⇒ Object
- #record(message, level = :info) ⇒ Object
- #record_fail(error) ⇒ Object
- #with_wrapper_logger(&block) ⇒ Object
- #with_wrapper_recorder(&block) ⇒ Object
Instance Method Details
#add_info(message) ⇒ Object
37 38 39 40 |
# File 'lib/worker_tools/recorder.rb', line 37 def add_info() @information ||= '' information << "#{()}\n" end |
#add_log(message, level = :info) ⇒ Object
33 34 35 |
# File 'lib/worker_tools/recorder.rb', line 33 def add_log(, level = :info) logger.public_send(level, ()) end |
#error_to_text(error, trace_lines = 20) ⇒ Object
79 80 81 82 |
# File 'lib/worker_tools/recorder.rb', line 79 def error_to_text(error, trace_lines = 20) txt = "Error: #{error.} (#{error.class})" txt << "Backtrace:\n#{error.backtrace[0, trace_lines].join("\n\t")}" end |
#format_info_message(message) ⇒ Object
53 54 55 56 57 |
# File 'lib/worker_tools/recorder.rb', line 53 def () return error_to_text(, info_error_trace_lines) if .is_a?(Exception) end |
#format_log_message(message) ⇒ Object
47 48 49 50 51 |
# File 'lib/worker_tools/recorder.rb', line 47 def () return error_to_text(, log_error_trace_lines) if .is_a?(Exception) end |
#info_error_trace_lines ⇒ Object
75 76 77 |
# File 'lib/worker_tools/recorder.rb', line 75 def info_error_trace_lines 20 end |
#log_directory ⇒ Object
63 64 65 |
# File 'lib/worker_tools/recorder.rb', line 63 def log_directory Rails.root.join('log') end |
#log_error_trace_lines ⇒ Object
71 72 73 |
# File 'lib/worker_tools/recorder.rb', line 71 def log_error_trace_lines 20 end |
#log_file_name ⇒ Object
67 68 69 |
# File 'lib/worker_tools/recorder.rb', line 67 def log_file_name "#{self.class.name.underscore.tr('/', '_')}.log" end |
#logger ⇒ Object
59 60 61 |
# File 'lib/worker_tools/recorder.rb', line 59 def logger @logger ||= Logger.new(File.join(log_directory, log_file_name)) end |
#record(message, level = :info) ⇒ Object
42 43 44 45 |
# File 'lib/worker_tools/recorder.rb', line 42 def record(, level = :info) add_log(, level) add_info() end |
#record_fail(error) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/worker_tools/recorder.rb', line 26 def record_fail(error) record "ID #{model.id} - Error" record(error, :error) model.information = information model.save!(validate: false) end |
#with_wrapper_logger(&block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/worker_tools/recorder.rb', line 15 def with_wrapper_logger(&block) block.yield # this time we do want to catch Exception to attempt to handle some of the # critical errors. # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:enable Lint/RescueException add_log(e, :error) raise end |
#with_wrapper_recorder(&block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/worker_tools/recorder.rb', line 4 def with_wrapper_recorder(&block) block.yield # this time we do want to catch Exception to attempt to handle some of the # critical errors. # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:enable Lint/RescueException record_fail(e) raise end |