-
Notifications
You must be signed in to change notification settings - Fork 1
/
rack_logs.rb
50 lines (37 loc) · 866 Bytes
/
rack_logs.rb
1
2
3
4
5
6
7
8
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
require 'rubygems'
require 'erb'
require 'sinatra'
require 'pp'
require 'lib/logs'
# set :logging, false
enable :sessions
before do
@logs = $logs
session['lines'] ||= "15"
session['refresh'] ||= "3"
session['lines'] = params['lines'] if params['lines']
session['refresh'] = params['refresh'] if params['refresh']
end
get '/' do
redirect '/log/0'
end
get '/log/:id' do
@log = @logs[params['id'].to_i]
@log_text = @log.get_some_log( session['lines'] )
erb :log
end
post '/log_text' do
@log = @logs[params['id'].to_i]
@log_text = @log.get_some_log( session['lines'] )
erb :log_text
end
post '/info_bar' do
@log = @logs[params['id'].to_i]
erb :path_info
end
configure do
$logs = []
logs_config = Logs.load_config_file
logs_config.each{ |log| $logs += Logs.add_logs(log)}
$logs.sort!{ |a,b| a.name <=> b.name }
end