Class: Indy
- Inherits:
-
Object
- Object
- Indy
- Defined in:
- lib/indy/indy.rb,
lib/indy/source.rb,
lib/indy/formats.rb,
lib/indy/version.rb,
lib/indy/log_formats.rb
Defined Under Namespace
Modules: LogFormats Classes: Source
Constant Summary
- VERSION =
'0.3.4'- DEFAULT_LOG_FORMAT =
Indy default log format e.g.: INFO 2000-09-07 MyApp - Entering APPLICATION.
[LogFormats::DEFAULT_LOG_REGEXP, LogFormats::DEFAULT_LOG_FIELDS].flatten
- LOG4R_DEFAULT_FORMAT =
Uncustomized Log4r log format
[LogFormats::LOG4R_DEFAULT_REGEXP, LogFormats::LOG4R_DEFAULT_FIELDS].flatten
- COMMON_LOG_FORMAT =
NCSA Common Log Format log format
[LogFormats::COMMON_REGEXP, LogFormats::COMMON_FIELDS].flatten
- COMBINED_LOG_FORMAT =
NCSA Combined Log Format log format
[LogFormats::COMBINED_REGEXP, LogFormats::COMBINED_FIELDS].flatten
Instance Attribute Summary (collapse)
-
- (Object) log_format
array with regexp string and capture groups followed by log field name symbols.
-
- (Object) multiline
initialization flag (true || nil) to enable multiline log entries.
-
- (Object) source
hash with one key (:string, :file, or :cmd) set to the string that defines the log.
-
- (Object) time_format
format string for explicit date/time format (optional).
Class Method Summary (collapse)
-
+ (Object) create_struct(line_hash)
Return a Struct::Line object from a hash of values from a log entry.
-
+ (Object) search(params = nil)
Create a new instance of Indy with @source, or multiple, parameters specified.
- + (Object) show_version_changes(version)
- + (Object) suppress_warnings {|block| ... }
Instance Method Summary (collapse)
-
- (Object) after(scope_criteria)
Scopes the eventual search to all entries after to this point.
- - (Object) around(scope_criteria)
-
- (Object) before(scope_criteria)
Scopes the eventual search to all entries prior to this point.
-
- (Object) for(search_criteria)
Search the source and make an == comparison.
-
- (Indy) initialize(args)
constructor
Initialize Indy.
-
- (Object) last(scope_criteria)
Scopes the eventual search to the last N entries, or last N minutes of entries.
-
- (Object) like(search_criteria)
(also: #matching)
Search the source and make a regular expression comparison.
-
- (Object) reset_scope
Removes any existing start and end times from the instance Otherwise consecutive search calls retain time scope state.
-
- (Object) with(log_format = :default)
Specify the log format to use as the comparison against each line within the log file that has been specified.
-
- (Object) within(scope_criteria)
Scopes the eventual search to all entries between two times.
Constructor Details
- (Indy) initialize(args)
Initialize Indy. Also see class method Indy.search()
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/indy/indy.rb', line 36 def initialize(args) @source = @log_format = @time_format = @log_regexp = @log_fields = @multiline = nil while (arg = args.shift) do send("#{arg.first}=",arg.last) end update_log_format( @log_format ) end |
Instance Attribute Details
- (Object) log_format
array with regexp string and capture groups followed by log field name symbols. :time field is required to use time scoping
17 18 19 |
# File 'lib/indy/indy.rb', line 17 def log_format @log_format end |
- (Object) multiline
initialization flag (true || nil) to enable multiline log entries. See README
23 24 25 |
# File 'lib/indy/indy.rb', line 23 def multiline @multiline end |
- (Object) source
hash with one key (:string, :file, or :cmd) set to the string that defines the log
13 14 15 |
# File 'lib/indy/indy.rb', line 13 def source @source end |
- (Object) time_format
format string for explicit date/time format (optional)
20 21 22 |
# File 'lib/indy/indy.rb', line 20 def time_format @time_format end |
Class Method Details
+ (Object) create_struct(line_hash)
Return a Struct::Line object from a hash of values from a log entry
94 95 96 97 |
# File 'lib/indy/indy.rb', line 94 def create_struct( line_hash ) params = line_hash.keys.sort_by{|e|e.to_s}.collect {|k| line_hash[k]} Struct::Line.new( *params ) end |
+ (Object) search(params = nil)
Create a new instance of Indy with @source, or multiple, parameters specified. This allows for a more fluent creation that moves into the execution.
80 81 82 83 84 85 86 87 |
# File 'lib/indy/indy.rb', line 80 def search(params=nil) if params.respond_to?(:keys) && params[:source] Indy.new(params) else Indy.new(:source => params, :log_format => DEFAULT_LOG_FORMAT) end end |
+ (Object) show_version_changes(version)
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 |
+ (Object) suppress_warnings {|block| ... }
5 6 7 8 9 10 |
# File 'lib/indy/indy.rb', line 5 def self.suppress_warnings(&block) verbose = $VERBOSE $VERBOSE = nil yield block $VERBOSE = verbose end |
Instance Method Details
- (Object) after(scope_criteria)
Scopes the eventual search to all entries after to this point.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/indy/indy.rb', line 212 def after(scope_criteria) if scope_criteria[:time] time = parse_date(scope_criteria[:time]) @inclusive = @inclusive || scope_criteria[:inclusive] || nil if scope_criteria[:span] span = (scope_criteria[:span].to_i * 60).seconds within(:time => [time, time + span]) else @start_time = time end end self end |
- (Object) around(scope_criteria)
263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/indy/indy.rb', line 263 def around(scope_criteria) if scope_criteria[:time] time = parse_date(scope_criteria[:time]) @inclusive = nil warn "Ignoring inclusive scope_criteria" if scope_criteria[:inclusive] half_span = ((scope_criteria[:span].to_i * 60)/2).seconds rescue 300.seconds within(:time => [time - half_span, time + half_span]) end self end |
- (Object) before(scope_criteria)
Scopes the eventual search to all entries prior to this point.
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/indy/indy.rb', line 247 def before(scope_criteria) if scope_criteria[:time] time = parse_date(scope_criteria[:time]) @inclusive = @inclusive || scope_criteria[:inclusive] || nil if scope_criteria[:span] span = (scope_criteria[:span].to_i * 60).seconds within(:time => [time - span, time], :inclusive => scope_criteria[:inclusive]) else @end_time = time end end self end |
- (Object) for(search_criteria)
Search the source and make an == comparison
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/indy/indy.rb', line 126 def for(search_criteria) results = ResultSet.new case search_criteria when Enumerable results += _search do |result| result_struct = Indy.create_struct(result) if search_criteria.reject {|criteria,value| result[criteria] == value }.empty? yield result_struct if block_given? and result_struct result_struct end when :all results += _search do |result| result_struct = Indy.create_struct(result) yield result_struct if block_given? result_struct end end results.compact end |
- (Object) last(scope_criteria)
Scopes the eventual search to the last N entries, or last N minutes of entries.
the last portion of the source
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/indy/indy.rb', line 183 def last(scope_criteria) case scope_criteria when Enumerable raise ArgumentError unless scope_criteria[:span] || scope_criteria[:rows] if scope_criteria[:span] span = (scope_criteria[:span].to_i * 60).seconds starttime = parse_date(last_entry[:_time]) - span within(:time => [starttime, forever]) end else raise ArgumentError, "Invalid parameter: #{scope_criteria.inspect}" end self end |
- (Object) like(search_criteria) Also known as: matching
Search the source and make a regular expression comparison
158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/indy/indy.rb', line 158 def like(search_criteria) results = ResultSet.new results += _search do |result| result_struct = Indy.create_struct(result) if search_criteria.reject {|criteria,value| result[criteria] =~ /#{value}/i }.empty? yield result_struct if block_given? and result_struct result_struct end results.compact end |
- (Object) reset_scope
Removes any existing start and end times from the instance Otherwise consecutive search calls retain time scope state
232 233 234 |
# File 'lib/indy/indy.rb', line 232 def reset_scope @inclusive = @start_time = @end_time = nil end |
- (Object) with(log_format = :default)
Specify the log format to use as the comparison against each line within the log file that has been specified.
114 115 116 117 |
# File 'lib/indy/indy.rb', line 114 def with(log_format = :default) update_log_format( log_format ) self end |
- (Object) within(scope_criteria)
Scopes the eventual search to all entries between two times.
288 289 290 291 292 293 294 295 296 |
# File 'lib/indy/indy.rb', line 288 def within(scope_criteria) if scope_criteria[:time] @start_time, @end_time = scope_criteria[:time].collect {|str| parse_date(str) } @inclusive = @inclusive || scope_criteria[:inclusive] || nil end self end |