Class: Indy
- Inherits:
-
Object
- Object
- Indy
- Defined in:
- lib/indy/indy.rb,
lib/indy/time.rb,
lib/indy/search.rb,
lib/indy/source.rb,
lib/indy/version.rb,
lib/indy/log_formats.rb,
lib/indy/log_definition.rb
Defined Under Namespace
Modules: LogFormats Classes: LogDefinition, Search, Source, Time
Constant Summary collapse
- VERSION =
'0.5.1'- DEFAULT_LOG_FORMAT =
Indy default log format e.g.: 2000-09-07 INFO MyApp - Entering APPLICATION.
{:entry_regexp => LogFormats::DEFAULT_ENTRY_REGEXP, :entry_fields => LogFormats::DEFAULT_ENTRY_FIELDS}
- LOG4R_DEFAULT_FORMAT =
Uncustomized Log4r log format
{:entry_regexp => LogFormats::LOG4R_DEFAULT_REGEXP, :entry_fields => LogFormats::LOG4R_DEFAULT_FIELDS}
- LOG4J_DEFAULT_FORMAT =
Uncustomized Log4j log format (message field only!)
{:entry_regexp => LogFormats::LOG4J_DEFAULT_REGEXP, :entry_fields => LogFormats::LOG4J_DEFAULT_FIELDS}
- COMMON_LOG_FORMAT =
NCSA Common Log Format log format
{:entry_regexp => LogFormats::COMMON_REGEXP, :entry_fields => LogFormats::COMMON_FIELDS, :time_format => LogFormats::COMMON_TIME_FORMAT}
- COMBINED_LOG_FORMAT =
NCSA Combined Log Format log format
{:entry_regexp => LogFormats::COMBINED_REGEXP, :entry_fields => LogFormats::COMBINED_FIELDS, :time_format => LogFormats::COMMON_TIME_FORMAT}
Instance Attribute Summary collapse
-
#search ⇒ Object
search object.
Class Method Summary collapse
-
.search(params = nil) ⇒ Object
Create a new instance of Indy specifying source, or multiple parameters.
- .show_version_changes(version) ⇒ Object
Instance Method Summary collapse
-
#after(scope_criteria) ⇒ Object
Scopes the eventual search to all entries after to this point.
-
#all(&block) ⇒ Object
Return all entries.
-
#around(scope_criteria) ⇒ Object
Scopes the eventual search to all entries near this point.
-
#before(scope_criteria) ⇒ Object
Scopes the eventual search to all entries prior to this point.
-
#for(search_criteria, &block) ⇒ Object
Search the source and make an == comparison.
-
#initialize(args) ⇒ Indy
constructor
Initialize Indy.
-
#last(scope_criteria) ⇒ Object
Scopes the eventual search to the last N minutes of entries.
-
#like(search_criteria, &block) ⇒ Object
(also: #matching)
Search the source and make a regular expression comparison.
-
#reset_scope ⇒ Object
Removes any existing start and end times from the instance Otherwise consecutive search calls retain time scope state.
-
#with(params = :default) ⇒ Object
Specify the log format to use as the comparison against each entry within the log file that has been specified.
-
#within(params) ⇒ Object
Scopes the eventual search to all entries between two times.
Constructor Details
#initialize(args) ⇒ Indy
Initialize Indy. Also see class method Indy#search.
16 17 18 19 20 21 22 23 |
# File 'lib/indy/indy.rb', line 16 def initialize(args) params = args.dup raise ArgumentError, "Source parameter not specified" unless (params.respond_to?(:keys) && params.keys.include?(:source)) source_param = params[:source] params.delete :source @search = Search.new() @search.source = Source.new( source_param, LogDefinition.new(params) ) end |
Instance Attribute Details
#search ⇒ Object
search object
4 5 6 |
# File 'lib/indy/indy.rb', line 4 def search @search end |
Class Method Details
.search(params = nil) ⇒ Object
Create a new instance of Indy specifying source, or multiple parameters.
47 48 49 50 51 52 53 |
# File 'lib/indy/indy.rb', line 47 def search(params=nil) if params.respond_to?(:keys) && params[:source] Indy.new(params) else Indy.new(:source => params, :entry_regexp => LogFormats::DEFAULT_ENTRY_REGEXP, :entry_fields => LogFormats::DEFAULT_ENTRY_FIELDS) end end |
.show_version_changes(version) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/indy/version.rb', line 6 def self.show_version_changes(version) date = "" changes = [] grab_changes = false File.open("#{File.dirname(__FILE__)}/../../History.txt",'r') do |file| while (line = file.gets) do if line =~ /^===\s*#{version.gsub('.','\.')}\s*\/\s*(.+)\s*$/ grab_changes = true date = $1.strip elsif line =~ /^===\s*.+$/ grab_changes = false elsif grab_changes changes = changes << line end end end { :date => date, :changes => changes } end |
Instance Method Details
#after(scope_criteria) ⇒ Object
Scopes the eventual search to all entries after to this point.
140 141 142 143 144 |
# File 'lib/indy/indy.rb', line 140 def after(scope_criteria) params = scope_criteria.merge({:direction => :after}) within(params) self end |
#all(&block) ⇒ Object
Return all entries
80 81 82 |
# File 'lib/indy/indy.rb', line 80 def all(&block) @search.iterate_and_compare(:all,nil,&block) end |
#around(scope_criteria) ⇒ Object
Scopes the eventual search to all entries near this point.
168 169 170 171 172 173 174 |
# File 'lib/indy/indy.rb', line 168 def around(scope_criteria) raise ArgumentError unless scope_criteria.respond_to?(:keys) and scope_criteria[:time] time = Indy::Time.parse_date(scope_criteria[:time], @search.source.log_definition.time_format) mid_span = ((scope_criteria[:span].to_i * 60)/2).seconds rescue 300.seconds within(:start_time => time - mid_span, :end_time => time + mid_span, :inclusive => nil) self end |
#before(scope_criteria) ⇒ Object
Scopes the eventual search to all entries prior to this point.
157 158 159 160 |
# File 'lib/indy/indy.rb', line 157 def before(scope_criteria) params = scope_criteria.merge({:direction => :before}) within(params) end |
#for(search_criteria, &block) ⇒ Object
Search the source and make an == comparison
90 91 92 |
# File 'lib/indy/indy.rb', line 90 def for(search_criteria,&block) @search.iterate_and_compare(:for,search_criteria,&block) end |
#last(scope_criteria) ⇒ Object
Scopes the eventual search to the last N minutes of entries.
120 121 122 123 124 125 126 127 |
# File 'lib/indy/indy.rb', line 120 def last(scope_criteria) raise ArgumentError, "Unsupported parameter to last(): #{scope_criteria.inspect}" unless scope_criteria.respond_to?(:keys) and scope_criteria[:span] span = (scope_criteria[:span].to_i * 60).seconds entry = last_entries(1)[0] start_time = Indy::Time.parse_date(entry[:time], @search.source.log_definition.time_format) - span within(:start_time => start_time, :end_time => Indy::Time.forever(@search.source.log_definition.time_format)) self end |
#like(search_criteria, &block) ⇒ Object Also known as: matching
Search the source and make a regular expression comparison
105 106 107 |
# File 'lib/indy/indy.rb', line 105 def like(search_criteria,&block) @search.iterate_and_compare(:like,search_criteria,&block) end |
#reset_scope ⇒ Object
Removes any existing start and end times from the instance Otherwise consecutive search calls retain time scope state
195 196 197 |
# File 'lib/indy/indy.rb', line 195 def reset_scope @search.reset_scope end |
#with(params = :default) ⇒ Object
Specify the log format to use as the comparison against each entry within the log file that has been specified.
69 70 71 72 73 74 75 |
# File 'lib/indy/indy.rb', line 69 def with(params=:default) if params.kind_of?(String) && params.match(/^Indy::/) params = params.constantize end @search.source.log_definition = LogDefinition.new(params) self end |
#within(params) ⇒ Object
Scopes the eventual search to all entries between two times.
186 187 188 189 |
# File 'lib/indy/indy.rb', line 186 def within(params) @search.time_scope(params) self end |