Class: AccessWatch::RackLogger
- Inherits:
-
Object
- Object
- AccessWatch::RackLogger
- Defined in:
- lib/access_watch/rack_logger.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, config) ⇒ RackLogger
constructor
A new instance of RackLogger.
- #record(env, status, started_at, finished_at) ⇒ Object
Constructor Details
#initialize(app, config) ⇒ RackLogger
5 6 7 |
# File 'lib/access_watch/rack_logger.rb', line 5 def initialize(app, config) @app, @client = app, AccessWatch::Client.new(config) end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
3 4 5 |
# File 'lib/access_watch/rack_logger.rb', line 3 def app @app end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/access_watch/rack_logger.rb', line 3 def client @client end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/access_watch/rack_logger.rb', line 9 def call(env) started_at = Time.now.utc status, headers, body = app.call(env) record(env, status, started_at, Time.now.utc) [status, headers, body] end |
#record(env, status, started_at, finished_at) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/access_watch/rack_logger.rb', line 16 def record(env, status, started_at, finished_at) post_request( time: started_at.iso8601(3), address: env["REMOTE_ADDR"], request: { protocol: env["HTTP_VERSION"], method: env["REQUEST_METHOD"], scheme: env["rack.url_scheme"], host: env["HTTP_HOST"], port: env["SERVER_PORT"], url: env["ORIGINAL_FULLPATH"], headers: extract_http_headers(env), }, response: {status: status}, context: { execution_time: finished_at - started_at, memory_usage: memory_usage_in_bytes, }, ) end |