Class: Hanami::Web::RackLogger Private
- Inherits:
-
Object
- Object
- Hanami::Web::RackLogger
- Defined in:
- lib/hanami/web/rack_logger.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Rack logger for Hanami apps
Defined Under Namespace
Modules: Development
Instance Method Summary collapse
- #attach(rack_monitor) ⇒ Object private
-
#initialize(logger, env: :development) ⇒ RackLogger
constructor
private
A new instance of RackLogger.
- #log_exception(env, exception, status, elapsed) ⇒ Object private
- #log_request(env, status, elapsed) ⇒ Object private
Constructor Details
#initialize(logger, env: :development) ⇒ RackLogger
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RackLogger.
58 59 60 61 |
# File 'lib/hanami/web/rack_logger.rb', line 58 def initialize(logger, env: :development) @logger = logger extend(Development) if %i[development test].include?(env) end |
Instance Method Details
#attach(rack_monitor) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/hanami/web/rack_logger.rb', line 65 def attach(rack_monitor) rack_monitor.on :stop do |event| log_request event[:env], event[:status], event[:time] end rack_monitor.on :error do |event| # TODO: why we don't provide time on error? log_exception event[:env], event[:exception], 500, 0 end end |
#log_exception(env, exception, status, elapsed) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 89 90 |
# File 'lib/hanami/web/rack_logger.rb', line 86 def log_exception(env, exception, status, elapsed) logger.tagged(:rack) do logger.error(exception, **data(env, status: status, elapsed: elapsed)) end end |
#log_request(env, status, elapsed) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
78 79 80 81 82 |
# File 'lib/hanami/web/rack_logger.rb', line 78 def log_request(env, status, elapsed) logger.tagged(:rack) do logger.info(data(env, status: status, elapsed: elapsed)) end end |