Class: SiteHub::Middleware::Logging::ErrorLogger
- Inherits:
-
Object
- Object
- SiteHub::Middleware::Logging::ErrorLogger
- Includes:
- Constants
- Defined in:
- lib/sitehub/middleware/logging/error_logger.rb
Constant Summary collapse
- LOG_TEMPLATE =
'[%s] ERROR: %s - %s'.freeze
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, logger = Logger.new(STDERR)) ⇒ ErrorLogger
constructor
A new instance of ErrorLogger.
- #log_message(error:, transaction_id:) ⇒ Object
Constructor Details
#initialize(app, logger = Logger.new(STDERR)) ⇒ ErrorLogger
Returns a new instance of ErrorLogger.
14 15 16 17 |
# File 'lib/sitehub/middleware/logging/error_logger.rb', line 14 def initialize(app, logger = Logger.new(STDERR)) @app = app @logger = LogWrapper.new(logger) end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/sitehub/middleware/logging/error_logger.rb', line 12 def logger @logger end |
Instance Method Details
#call(env) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sitehub/middleware/logging/error_logger.rb', line 19 def call(env) errors = env[ERRORS] ||= LogStash.new @app.call(env).tap do unless errors.empty? = errors.collect do |log_entry| (error: log_entry., transaction_id: env[RackHttpHeaderKeys::TRANSACTION_ID]) end logger.write(.join(NEW_LINE)) end end end |
#log_message(error:, transaction_id:) ⇒ Object
32 33 34 |
# File 'lib/sitehub/middleware/logging/error_logger.rb', line 32 def (error:, transaction_id:) format(LOG_TEMPLATE, Time.now.strftime(TIME_STAMP_FORMAT), transaction_id, error) end |