Class: Racknga::Middleware::Log — racknga - ラングバ

Class: Racknga::Middleware::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/racknga/middleware/log.rb

Overview

This is a middleware that puts access logs to groonga database. It may useful for OLAP (OnLine Analytical Processing).

Usage:

use Racnkga::Middleware::Log, :database_path => "var/log/db"
run YourApplication

See Also:

Defined Under Namespace

Classes: Logger

Constant Summary

LOGGER =
"racknga.logger"

Instance Method Summary (collapse)

Constructor Details

- (Log) initialize(application, options = {})

database path to be stored caches.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :database_path (String)

    the

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
44
# File 'lib/racknga/middleware/log.rb', line 37

def initialize(application, options={})
  @application = application
  @options = Utils.normalize_options(options || {})
  database_path = @options[:database_path]
  raise ArgumentError, ":database_path is missing" if database_path.nil?
  @database = LogDatabase.new(database_path)
  @logger = Logger.new(@database)
end

Instance Method Details

- (Object) call(environment)

For Rack.



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/racknga/middleware/log.rb', line 47

def call(environment)
  environment[LOGGER] = @logger

  start_time = Time.now
  status, headers, body = @application.call(environment)
  end_time = Time.now

  request = Rack::Request.new(environment)
  log(start_time, end_time, request, status, headers, body)

  [status, headers, body]
end

- (Object) close_database

close the cache database.



66
67
68
# File 'lib/racknga/middleware/log.rb', line 66

def close_database
  @database.close_database
end

- (Object) ensure_database

ensures creating cache database.



61
62
63
# File 'lib/racknga/middleware/log.rb', line 61

def ensure_database
  @database.ensure_database
end