Class: RightScraper::Loggers::Base
- Inherits:
-
Logger
- Object
- Logger
- RightScraper::Loggers::Base
- Defined in:
- lib/right_scraper/loggers/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#warnings ⇒ Object
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Base
constructor
A new instance of Base.
-
#note_error(exception, type, explanation = nil) ⇒ TrueClass
Note an error, with the given exception and explanation of what was going on.
-
#note_phase(phase, type, explanation, exception = nil) ⇒ TrueClass
Note a phase change within an operation.
-
#note_warning(message) ⇒ TrueClass
Note a warning for current operation.
-
#operation(type, explanation = '') { ... } ⇒ Object
Encapsulates an operation that merits logging.
Constructor Details
#initialize(*args) ⇒ Base
Returns a new instance of Base.
35 36 37 38 39 40 41 |
# File 'lib/right_scraper/loggers/base.rb', line 35 def initialize(*args) super(*args) @abort_seen = false @callback = nil @errors = [] @warnings = [] end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
33 34 35 |
# File 'lib/right_scraper/loggers/base.rb', line 33 def callback @callback end |
#errors ⇒ Object
Returns the value of attribute errors.
33 34 35 |
# File 'lib/right_scraper/loggers/base.rb', line 33 def errors @errors end |
#warnings ⇒ Object
Returns the value of attribute warnings.
33 34 35 |
# File 'lib/right_scraper/loggers/base.rb', line 33 def warnings @warnings end |
Instance Method Details
#note_error(exception, type, explanation = nil) ⇒ TrueClass
Note an error, with the given exception and explanation of what was going on.
96 97 98 |
# File 'lib/right_scraper/loggers/base.rb', line 96 def note_error(exception, type, explanation = nil) raise NotImplementedError end |
#note_phase(phase, type, explanation, exception = nil) ⇒ TrueClass
Note a phase change within an operation.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/right_scraper/loggers/base.rb', line 71 def note_phase(phase, type, explanation, exception = nil) @callback.call(phase, type, explanation, exception) if @callback case phase when :begin @abort_seen = false when :commit # do nothing when :abort unless @abort_seen note_error(exception, type, explanation) @abort_seen = true end else fail 'Unknown phase' end end |
#note_warning(message) ⇒ TrueClass
Note a warning for current operation.
107 108 109 |
# File 'lib/right_scraper/loggers/base.rb', line 107 def note_warning() raise NotImplementedError end |
#operation(type, explanation = '') { ... } ⇒ Object
Encapsulates an operation that merits logging.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/right_scraper/loggers/base.rb', line 51 def operation(type, explanation = '') begin note_phase(:begin, type, explanation) result = yield note_phase(:commit, type, explanation) result rescue Exception => e note_phase(:abort, type, explanation, e) raise end end |