Class: Rack::XrkLog::Base
- Inherits:
-
Object
- Object
- Rack::XrkLog::Base
- Defined in:
- lib/rack/xrk/adapter/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#begin_at ⇒ Object
Returns the value of attribute begin_at.
-
#log_type ⇒ Object
Returns the value of attribute log_type.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #formatter ⇒ Object
-
#initialize(app, app_name) ⇒ Base
constructor
A new instance of Base.
- #stop_at ⇒ Object
- #total_runtime ⇒ Object
- #write(env, body, status, header) ⇒ Object
Constructor Details
#initialize(app, app_name) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 12 13 14 |
# File 'lib/rack/xrk/adapter/base.rb', line 6 def initialize(app, app_name) app_name = app_name @app = app @log_type = "ACCESS" @logger = ::Logger.new("log/#{app_name}_quality_access.log") @logger.formatter = proc do |severity, datetime, progname, msg| "#{begin_at}|#{app_name}|#{log_type}|#{msg}\n" end end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
4 5 6 |
# File 'lib/rack/xrk/adapter/base.rb', line 4 def app @app end |
#app_name ⇒ Object
Returns the value of attribute app_name.
4 5 6 |
# File 'lib/rack/xrk/adapter/base.rb', line 4 def app_name @app_name end |
#begin_at ⇒ Object
Returns the value of attribute begin_at.
4 5 6 |
# File 'lib/rack/xrk/adapter/base.rb', line 4 def begin_at @begin_at end |
#log_type ⇒ Object
Returns the value of attribute log_type.
4 5 6 |
# File 'lib/rack/xrk/adapter/base.rb', line 4 def log_type @log_type end |
#logger ⇒ Object
Returns the value of attribute logger.
4 5 6 |
# File 'lib/rack/xrk/adapter/base.rb', line 4 def logger @logger end |
Instance Method Details
#formatter ⇒ Object
16 17 18 |
# File 'lib/rack/xrk/adapter/base.rb', line 16 def formatter raise NotImplementedError.new("You must implemente #{name} formatter method!") end |
#stop_at ⇒ Object
24 25 26 |
# File 'lib/rack/xrk/adapter/base.rb', line 24 def stop_at DateTime.now.strftime("%Q").to_i end |
#total_runtime ⇒ Object
20 21 22 |
# File 'lib/rack/xrk/adapter/base.rb', line 20 def total_runtime stop_at - begin_at end |
#write(env, body, status, header) ⇒ Object
28 29 30 31 |
# File 'lib/rack/xrk/adapter/base.rb', line 28 def write(env, body, status, header) body = formatter(env, body, status, header) @logger.info(body) unless body.nil? end |