9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/log_file.rb', line 9
def call(env={})
if env["PATH_INFO"]=~/^\/log_file/
@log_name=((Rails.env=="development")?("log/development.log"):("log/production.log"))
@lines=`wc -l <"#{ @log_name }"`.to_i
if(env["QUERY_STRING"]=~/direction/ )
if(env["QUERY_STRING"]=="direction=Next")
count=@lines-env['rack.session'][:line_count]
env['rack.session'][:line_count]=@lines
env['rack.session'][:displayed_lines] += count
data=`tail -n "#{ count }" "#{ @log_name }"`
[200,{"Content-Type"=>"text/html"},[view_append(data)]]
elsif(env["QUERY_STRING"]=="direction=Previous")
lines_added=@lines-env['rack.session'][:line_count]
bottom_stack=env['rack.session'][:displayed_lines]+lines_added
previous_lines=(@lines-bottom_stack)
if previous_lines>=30
env['rack.session'][:displayed_lines] += 30
data=`head -n "#{ previous_lines }" "#{ @log_name }" | tail -30`
[200,{"Content-Type"=>"text/html"},[view_append(data)]]
elsif((previous_lines<30)&&(previous_lines>0))
env['rack.session'][:displayed_lines] += previous_lines
data=`head -"#{ previous_lines }" "#{ @log_name }"`
[200,{"Content-Type"=>"text/html"},[view_append(data)]]
else
[200,{"Content-Type"=>"text/html"},[""]]
end
end
else
env['rack.session'][:line_count]=@lines
if @lines>=30
env['rack.session'][:displayed_lines]=count=30
else
env['rack.session'][:displayed_lines]=count=@lines
end
data=`tail -"#{ count }" "#{ @log_name }"`
[200,{"Content-Type"=>"text/html"},[view_generate(data)]]
end
else
@app.call(env)
end
end
|