Class: Racknga::LogDatabase
- Inherits:
-
Object
- Object
- Racknga::LogDatabase
- Defined in:
- lib/racknga/log_database.rb
Overview
This is a log database based on groonga. It is used by Racknga::Middleware::Log.
Normally, #purge_old_responses is only used for log maintenance.
Instance Method Summary (collapse)
- - (Object) close_database
- - (Object) ensure_database
- - (Object) entries
-
- (LogDatabase) initialize(database_path)
constructor
A new instance of LogDatabase.
-
- (Object) purge_old_entries(base_time = nil)
Purges old responses.
Constructor Details
- (LogDatabase) initialize(database_path)
A new instance of LogDatabase
31 32 33 34 35 |
# File 'lib/racknga/log_database.rb', line 31 def initialize(database_path) @database_path = database_path @context = Groonga::Context.new(:encoding => :none) ensure_database end |
Instance Method Details
- (Object) close_database
50 51 52 |
# File 'lib/racknga/log_database.rb', line 50 def close_database @database.close end |
- (Object) ensure_database
41 42 43 44 45 46 47 48 |
# File 'lib/racknga/log_database.rb', line 41 def ensure_database if File.exist?(@database_path) @database = Groonga::Database.open(@database_path, :context => @context) else create_database end ensure_tables end |
- (Object) entries
37 38 39 |
# File 'lib/racknga/log_database.rb', line 37 def entries @entries ||= @context["Entries"] end |
- (Object) purge_old_entries(base_time = nil)
Purges old responses. To clear old logs, you should call this method. All records created before base_time are removed.
You can call this method by the different process from your Rack application process. (e.g. cron.) It’s multi process safe.
removed. The default value is 1 day ago.
64 65 66 67 68 69 70 71 72 |
# File 'lib/racknga/log_database.rb', line 64 def purge_old_entries(base_time=nil) base_time ||= Time.now - 60 * 60 * 24 target_entries = entries.select do |record| record.time_stamp < base_time end target_entries.each do |entry| entry.key.delete end end |