Class: FullRequestLogger::Recorder
- Inherits:
-
Object
- Object
- FullRequestLogger::Recorder
- Defined in:
- lib/full_request_logger/recorder.rb
Instance Attribute Summary collapse
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
Class Method Summary collapse
Instance Method Summary collapse
-
#attach_to(logger) ⇒ Object
Extends an existing logger instance with a broadcast aspect that’ll send a copy of all logging lines to this recorder.
-
#close ⇒ Object
no-op needed for Logger to treat this as a valid log device.
-
#combined_log ⇒ Object
Return a single string with all the log messages that have been buffered so far.
-
#initialize ⇒ Recorder
constructor
A new instance of Recorder.
-
#reset ⇒ Object
Clear out any messages pending in the buffer as well as all existing stored request logs.
-
#retrieve(request_id) ⇒ Object
Returns a single string with all the log messages that were captured for the given
request_id(or nil if nothing was recorded or it has since expired). -
#store(request_id) ⇒ Object
Store all log messages as a single string to the full request logging storage accessible under the
request_id. -
#write(message) ⇒ Object
Writes a log message to a buffer that’ll be stored when the request is over.
Constructor Details
#initialize ⇒ Recorder
Returns a new instance of Recorder.
13 14 15 |
# File 'lib/full_request_logger/recorder.rb', line 13 def initialize @redis = Redis.new FullRequestLogger.redis end |
Instance Attribute Details
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
7 8 9 |
# File 'lib/full_request_logger/recorder.rb', line 7 def redis @redis end |
Class Method Details
.instance ⇒ Object
9 10 11 |
# File 'lib/full_request_logger/recorder.rb', line 9 def self.instance @instance ||= new end |
Instance Method Details
#attach_to(logger) ⇒ Object
Extends an existing logger instance with a broadcast aspect that’ll send a copy of all logging lines to this recorder.
18 19 20 |
# File 'lib/full_request_logger/recorder.rb', line 18 def attach_to(logger) logger.extend ActiveSupport::Logger.broadcast(ActiveSupport::Logger.new(self)) end |
#close ⇒ Object
no-op needed for Logger to treat this as a valid log device
59 60 61 |
# File 'lib/full_request_logger/recorder.rb', line 59 def close redis.disconnect! end |
#combined_log ⇒ Object
Return a single string with all the log messages that have been buffered so far.
28 29 30 |
# File 'lib/full_request_logger/recorder.rb', line 28 def combined_log .join.strip end |
#reset ⇒ Object
Clear out any messages pending in the buffer as well as all existing stored request logs.
53 54 55 56 |
# File 'lib/full_request_logger/recorder.rb', line 53 def reset .clear clear_stored_requests end |
#retrieve(request_id) ⇒ Object
Returns a single string with all the log messages that were captured for the given request_id (or nil if nothing was recorded or it has since expired).
46 47 48 49 50 |
# File 'lib/full_request_logger/recorder.rb', line 46 def retrieve(request_id) if log = redis.get(request_key(request_id)) uncompress(log).force_encoding("utf-8") end end |
#store(request_id) ⇒ Object
Store all log messages as a single string to the full request logging storage accessible under the request_id.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/full_request_logger/recorder.rb', line 33 def store(request_id) if (log_to_be_stored = combined_log).present? redis.setex \ request_key(request_id), FullRequestLogger.ttl, compress(log_to_be_stored) end ensure .clear end |
#write(message) ⇒ Object
Writes a log message to a buffer that’ll be stored when the request is over.
23 24 25 |
# File 'lib/full_request_logger/recorder.rb', line 23 def write() << remove_ansi_colors() end |