Initialize Analyse-Console
This commit is contained in:
parent
338daed210
commit
7aa766163a
2 changed files with 61 additions and 0 deletions
12
bin/logansh
Executable file
12
bin/logansh
Executable file
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'logan/analyse'
|
||||
require 'active_support'
|
||||
require 'irb'
|
||||
|
||||
$logan = LogAn::Analyse.new 'logs'
|
||||
begin
|
||||
IRB.start __FILE__
|
||||
ensure
|
||||
$logan.close
|
||||
end
|
49
lib/logan/analyse.rb
Normal file
49
lib/logan/analyse.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
|
||||
require 'logan/loglines'
|
||||
require 'time'
|
||||
|
||||
class LogAn::Analyse
|
||||
attr_reader :lines
|
||||
|
||||
def close
|
||||
@lines.close
|
||||
end
|
||||
|
||||
def initialize lines
|
||||
@lines = String === lines ? LogAn::Loglines.new( lines) : lines
|
||||
end
|
||||
|
||||
def extremum val
|
||||
val = case val
|
||||
when String then Time.parse val
|
||||
when Integer then Time.at val
|
||||
when Time then val
|
||||
else raise ArgumentError, "Unknwon type: #{val}", caller[ 1..-1]
|
||||
end
|
||||
end
|
||||
|
||||
def timerange min, max = nil
|
||||
exend = false
|
||||
min, max, exend = min.min, min.max, min.exclude_end? if Range === min
|
||||
Range.new extremum( min), extremum( max), exend
|
||||
end
|
||||
|
||||
def dbs min, max = nil, &exe
|
||||
return Enumerator.new( self, :dbs, min, max) unless exe
|
||||
range = timerange min, max
|
||||
@lines.rdb.each &exe
|
||||
end
|
||||
|
||||
def search min, max = nil, &exe
|
||||
dbs = @lines.dbs
|
||||
range = timerange min, max
|
||||
@lines.rdb.each do |time, db|
|
||||
dbs[ UUIDTools::UUID.parse_raw( db)].each &exe if range === Time.at( *time.unpack( 'N'))
|
||||
end
|
||||
end
|
||||
alias [] search
|
||||
|
||||
def each min, max = nil, &exe
|
||||
exe ? search( min, max, &exe) : Enumerator.new( self, :search, min, max)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue