Class: Epuber::Logger::AbstractLogger
- Inherits:
-
Object
- Object
- Epuber::Logger::AbstractLogger
- Defined in:
- lib/epuber/utils/logger/abstract_logger.rb
Direct Known Subclasses
Constant Summary collapse
- LEVELS =
%i[ error warning info debug ].freeze
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#debug(message, sticky: false, location: nil, backtrace: caller_locations) ⇒ Object
Report debug message.
- #end_processing ⇒ Object
-
#error(message, sticky: false, location: nil, backtrace: caller_locations) ⇒ Object
Report error message.
-
#error!(message, location: nil, backtrace: caller_locations) ⇒ Object
Report error message.
-
#error? ⇒ Boolean
Return true if there was any error logged.
-
#info(message, sticky: false, location: nil, backtrace: caller_locations) ⇒ Object
Report info message.
-
#initialize(opts = {}) ⇒ AbstractLogger
constructor
A new instance of AbstractLogger.
- #print_processing_debug_info(info_text) ⇒ Object
- #print_step_processing_time(step_name, time = nil) ⇒ Object
- #start_processing_file(file, index, count) ⇒ Object
-
#warning(message, sticky: false, location: nil, backtrace: caller_locations) ⇒ Object
Report warning message.
Constructor Details
#initialize(opts = {}) ⇒ AbstractLogger
Returns a new instance of AbstractLogger.
30 31 32 33 34 35 36 37 |
# File 'lib/epuber/utils/logger/abstract_logger.rb', line 30 def initialize(opts = {}) @verbose = opts.fetch(:verbose, false) @debug_steps_times = opts.fetch(:debug_steps_times, false) @current_file = nil @sticky_message = nil @error_was_logged = false end |
Instance Attribute Details
#debug_steps_times ⇒ Boolean
24 25 26 |
# File 'lib/epuber/utils/logger/abstract_logger.rb', line 24 def debug_steps_times @debug_steps_times end |
#verbose ⇒ Boolean
20 21 22 |
# File 'lib/epuber/utils/logger/abstract_logger.rb', line 20 def verbose @verbose end |
Instance Method Details
#debug(message, sticky: false, location: nil, backtrace: caller_locations) ⇒ Object
Report debug message
83 84 85 86 87 |
# File 'lib/epuber/utils/logger/abstract_logger.rb', line 83 def debug(, sticky: false, location: nil, backtrace: caller_locations) return unless @verbose _common_log(:debug, , sticky: sticky, location: location, backtrace: backtrace) end |
#end_processing ⇒ Object
99 100 101 102 |
# File 'lib/epuber/utils/logger/abstract_logger.rb', line 99 def end_processing @current_file = nil end |
#error(message, sticky: false, location: nil, backtrace: caller_locations) ⇒ Object
Report error message
56 57 58 |
# File 'lib/epuber/utils/logger/abstract_logger.rb', line 56 def error(, sticky: false, location: nil, backtrace: caller_locations) _common_log(:error, , sticky: sticky, location: location, backtrace: backtrace) end |
#error!(message, location: nil, backtrace: caller_locations) ⇒ Object
Report error message
45 46 47 48 |
# File 'lib/epuber/utils/logger/abstract_logger.rb', line 45 def error!(, location: nil, backtrace: caller_locations) _common_log(:error, , location: location, backtrace: backtrace) exit(1) end |
#error? ⇒ Boolean
Return true if there was any error logged
145 146 147 |
# File 'lib/epuber/utils/logger/abstract_logger.rb', line 145 def error? @error_was_logged end |
#info(message, sticky: false, location: nil, backtrace: caller_locations) ⇒ Object
Report info message
74 75 76 |
# File 'lib/epuber/utils/logger/abstract_logger.rb', line 74 def info(, sticky: false, location: nil, backtrace: caller_locations) _common_log(:info, , sticky: sticky, location: location, backtrace: backtrace) end |
#print_processing_debug_info(info_text) ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/epuber/utils/logger/abstract_logger.rb', line 106 def print_processing_debug_info(info_text) return unless @verbose = if @current_file.nil? "▸ #{info_text}" else "▸ #{@current_file.source_path}: #{info_text}" end _log(:debug, ) end |
#print_step_processing_time(step_name, time = nil) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/epuber/utils/logger/abstract_logger.rb', line 120 def print_step_processing_time(step_name, time = nil) return yield unless @debug_steps_times if block_given? start = Time.now returned_value = yield time = Time.now - start end info_text = "Step #{step_name} took #{(time * 1000).round(2)} ms" = if @current_file.nil? "▸ #{info_text}" else "▸ #{@current_file.source_path}: #{info_text}" end _log(:debug, ) returned_value end |
#start_processing_file(file, index, count) ⇒ Object
93 94 95 96 97 |
# File 'lib/epuber/utils/logger/abstract_logger.rb', line 93 def start_processing_file(file, index, count) @current_file = file _common_log(:debug, "▸ Processing #{file.source_path} (#{index + 1} of #{count})", sticky: true) end |
#warning(message, sticky: false, location: nil, backtrace: caller_locations) ⇒ Object
Report warning message
65 66 67 |
# File 'lib/epuber/utils/logger/abstract_logger.rb', line 65 def warning(, sticky: false, location: nil, backtrace: caller_locations) _common_log(:warning, , sticky: sticky, location: location, backtrace: backtrace) end |