Class: RightScraper::Loggers::Default
- Defined in:
- lib/right_scraper/loggers/default.rb
Overview
provides a default scraper logger implementation that accumulates errors and warnings but otherwise is a null logger.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#add(severity, message = nil, progname = nil) ⇒ Object
overrides ::Logger#add in order to record errors and warnings logged via the normal logger interface.
-
#initialize(*args) ⇒ Default
constructor
A new instance of Default.
-
#note_error(exception, type, explanation = '') ⇒ Object
implements Interface#note_error.
-
#note_warning(message) ⇒ Object
implements Interface#note_warning.
Methods inherited from Base
Constructor Details
#initialize(*args) ⇒ Default
Returns a new instance of Default.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/right_scraper/loggers/default.rb', line 33 def initialize(*args) if args.empty? is_windows = !!(RUBY_PLATFORM =~ /mswin|win32|dos|mingw|cygwin/) super(is_windows ? 'nul' : '/dev/null') else super(*args) end self.level = ::Logger::ERROR @recording_messages = true end |
Instance Method Details
#add(severity, message = nil, progname = nil) ⇒ Object
overrides ::Logger#add in order to record errors and warnings logged via the normal logger interface.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/right_scraper/loggers/default.rb', line 63 def add(severity, = nil, progname = nil) if severity >= self.level # super logger. if .nil? if block_given? = yield else = progname progname = self.progname end end super(severity, , progname) # record errors (with detail) and warnings. if @recording_messages if severity >= Logger::ERROR @errors << [nil, :log, ] elsif severity == ::Logger::WARN @warnings << end end end true end |
#note_error(exception, type, explanation = '') ⇒ Object
implements Interface#note_error
45 46 47 48 49 50 51 52 53 |
# File 'lib/right_scraper/loggers/default.rb', line 45 def note_error(exception, type, explanation = '') do explanation = explanation.to_s.strip = "Saw #{exception ? exception. : 'error'} during #{type}" += ": #{explanation}" unless explanation.empty? error() end @errors << [exception, type, explanation] end |
#note_warning(message) ⇒ Object
implements Interface#note_warning
56 57 58 59 |
# File 'lib/right_scraper/loggers/default.rb', line 56 def note_warning() { warn() } @warnings << end |