Class: Card::Log::Request

Inherits:
Object show all
Defined in:
lib/card/log.rb

Class Method Summary collapse

Class Method Details

.pathObject



7
8
9
10
11
# File 'lib/card/log.rb', line 7

def self.path
  path = (Card.paths['request_log'] && Card.paths['request_log'].first) || File.dirname(Card.paths['log'].first)
  filename = "#{Date.today}_#{Rails.env}.csv"
  File.join path, filename
end

.write_log_entry(controller) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/card/log.rb', line 13

def self.write_log_entry controller
  return if controller.env["REQUEST_URI"] =~ %r{^/files?/}

  controller.instance_eval do
    log = []
    log << (Card::Env.ajax? ? "YES" : "NO")
    log << env["REMOTE_ADDR"]
    log << Card::Auth.current_id
    log << card.name
    log << action_name
    log << params['view'] || (s = params['success'] and  s['view'])
    log << env["REQUEST_METHOD"]
    log << status
    log << env["REQUEST_URI"]
    log << DateTime.now.to_s
    log << env['HTTP_ACCEPT_LANGUAGE'].to_s.scan(/^[a-z]{2}/).first
    log << env["HTTP_REFERER"]

    File.open(Card::Log::Request.path, "a") do |f|
      f.write CSV.generate_line(log)
    end
  end
end