Class: Rack::XrkLog::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/xrk/adapter/base.rb

Direct Known Subclasses

Dispose

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#appObject

Returns the value of attribute app.



4
5
6
# File 'lib/rack/xrk/adapter/base.rb', line 4

def app
  @app
end

#app_nameObject

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_atObject

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_typeObject

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

#loggerObject

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

#formatterObject

Raises:

  • (NotImplementedError)


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_atObject



24
25
26
# File 'lib/rack/xrk/adapter/base.rb', line 24

def stop_at
  DateTime.now.strftime("%Q").to_i
end

#total_runtimeObject



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