Class: RightScraper::Logger
- Inherits:
-
Logger
- Object
- Logger
- RightScraper::Logger
- Defined in:
- lib/right_scraper/logger.rb
Overview
Very simplistic logger for scraper operations.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#repository ⇒ Object
writeonly
(RightScraper::Repositories::Base) Repository currently being examined.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Logger
constructor
If no arguments, create a Logger that logs to nothing.
-
#note_error(exception, type, explanation = "") ⇒ Object
Log an error, with the given exception and explanation of what was going on.
-
#note_phase(phase, type, explanation, exception = nil) ⇒ Object
Note an event to the log.
- #note_warning(message) ⇒ Object
-
#operation(type, explanation = "") ⇒ Object
Begin an operation that merits logging.
Constructor Details
#initialize(*args) ⇒ Logger
If no arguments, create a Logger that logs to nothing. Otherwise pass the arguments on to ::Logger.
31 32 33 34 35 36 37 38 39 |
# File 'lib/right_scraper/logger.rb', line 31 def initialize(*args) if args.empty? super('/dev/null') self.level = ::Logger::ERROR else super end @exceptional = false end |
Instance Attribute Details
#repository=(value) ⇒ Object (writeonly)
(RightScraper::Repositories::Base) Repository currently being examined.
42 43 44 |
# File 'lib/right_scraper/logger.rb', line 42 def repository=(value) @repository = value end |
Instance Method Details
#note_error(exception, type, explanation = "") ⇒ Object
Log an error, with the given exception and explanation of what was going on.
Parameters
- exception(Exception)
-
exception raised
- type(Symbol)
-
operation type identifier
- explanation(String)
-
optional explanation
89 90 91 |
# File 'lib/right_scraper/logger.rb', line 89 def note_error(exception, type, explanation="") error("Saw #{exception} during #{type}#{maybe_explain(explanation)}") end |
#note_phase(phase, type, explanation, exception = nil) ⇒ Object
Note an event to the log. In this base class this calls note_error when an error occurs, but subclasses will presumably want to override it.
Parameters
- phase(Symbol)
-
phase of operation; one of :begin, :commit, :abort
- type(Symbol)
-
operation type identifier
- explanation(String)
-
explanation of operation
- exception(Exception)
-
optional exception (only if
phase
is :abort)
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/right_scraper/logger.rb', line 71 def note_phase(phase, type, explanation, exception=nil) case phase when :begin then @exceptional = false when :abort then unless @exceptional note_error(exception, type, explanation) @exceptional = true end end end |
#note_warning(message) ⇒ Object
93 94 95 |
# File 'lib/right_scraper/logger.rb', line 93 def note_warning() warn() end |
#operation(type, explanation = "") ⇒ Object
Begin an operation that merits logging. Will call #note_error if an exception is raised during the operation.
Parameters
- type(Symbol)
-
operation type identifier
- explanation(String)
-
optional explanation
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/right_scraper/logger.rb', line 50 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 |