tailog 0.1.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/views/error.erb +6 -0
- data/app/views/{index.erb → logs/index.erb} +35 -40
- data/app/views/logs/list.erb +3 -0
- data/lib/tailog/version.rb +1 -1
- data/lib/tailog.rb +31 -5
- metadata +4 -3
- data/app/views/ajax.erb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94898f11ab8489deacbdd01e07f902ac201740f3
|
4
|
+
data.tar.gz: 4d42e7d30f37d856c349e3ffadc5a91d070fde1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c0ceab245395356fbc3ba8be2e8c7ef943814e54dcafbde612c496a4dd5b6d8069fe0acaca37cc3e44bbb84fc92952e625b18c0e313aa7751ba305917fce8f2
|
7
|
+
data.tar.gz: 90be1575fd13c56462793d667298f880ecf1c3334af0a4374b908a654642971957e14ff63f5cc5c1d39030a404cced5ba38d46ce877b3951b6dbd3d5df0e98c1
|
data/app/views/error.erb
ADDED
@@ -64,43 +64,43 @@
|
|
64
64
|
<% file_path = File.join Tailog.log_path, params[:file] %>
|
65
65
|
<h3 class="page-header monospace"><%= file_path %></h3>
|
66
66
|
|
67
|
-
<% File.open file_path do |file| %>
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
window.
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
if (
|
88
|
-
|
89
|
-
|
90
|
-
|
67
|
+
<% File.open file_path do |file| end %>
|
68
|
+
<div id="content" class="monospace"></div>
|
69
|
+
|
70
|
+
<script type="text/javascript">
|
71
|
+
window.fileSize = {};
|
72
|
+
window.fileSizeDone = {};
|
73
|
+
var $window = $(window),
|
74
|
+
$document = $(document),
|
75
|
+
$content = $("#content");
|
76
|
+
|
77
|
+
function loadMore() {
|
78
|
+
$.post(window.location.href, { seek: window.fileSize }, function(json) {
|
79
|
+
try {
|
80
|
+
var data = JSON.parse(json);
|
81
|
+
|
82
|
+
var fileSizeKey = data.server_uuid + '-' + data.file_size;
|
83
|
+
if (window.fileSizeDone[fileSizeKey]) return;
|
84
|
+
window.fileSizeDone[fileSizeKey] = true;
|
85
|
+
window.fileSize[data.server_uuid] = data.file_size;
|
86
|
+
|
87
|
+
if (!data.content) return;
|
88
|
+
var shouldScrollToBottom = $window.scrollTop() + $window.height() == $document.height();
|
89
|
+
$(data.content).appendTo($content);
|
90
|
+
|
91
|
+
if (shouldScrollToBottom) {
|
92
|
+
$window.scrollTop($document.height() - $window.height());
|
91
93
|
}
|
92
94
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
}
|
99
|
-
});
|
100
|
-
}, 3000);
|
101
|
-
</script>
|
95
|
+
} catch (error) {
|
96
|
+
console.log(error)
|
97
|
+
}
|
98
|
+
});
|
99
|
+
}
|
102
100
|
|
103
|
-
|
101
|
+
setInterval(loadMore, 3000);
|
102
|
+
loadMore();
|
103
|
+
</script>
|
104
104
|
|
105
105
|
<% else %>
|
106
106
|
<div id="content" class="monospace">
|
@@ -112,12 +112,7 @@
|
|
112
112
|
<% end %>
|
113
113
|
|
114
114
|
<% rescue => error %>
|
115
|
-
|
116
|
-
<h4><%= h error.class %>: <%= h error.message %></h4>
|
117
|
-
<% error.backtrace.each do |backtrace| %>
|
118
|
-
<%= h backtrace %><br>
|
119
|
-
<% end %>
|
120
|
-
</div>
|
115
|
+
<%= erb :error, locals: { error: error } %>
|
121
116
|
<% end %>
|
122
117
|
|
123
118
|
</div> <!-- /container -->
|
data/lib/tailog/version.rb
CHANGED
data/lib/tailog.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'tailog/version'
|
2
|
-
require 'tailog/ext/file'
|
3
2
|
require 'sinatra/base'
|
4
3
|
require 'active_support/configurable'
|
4
|
+
require 'tailog/ext/file'
|
5
|
+
require 'securerandom'
|
6
|
+
require 'json'
|
5
7
|
|
6
8
|
module Tailog
|
7
9
|
include ActiveSupport::Configurable
|
@@ -10,6 +12,10 @@ module Tailog
|
|
10
12
|
File.expand_path("log", Dir.pwd)
|
11
13
|
end
|
12
14
|
|
15
|
+
config_accessor :server_uuid do
|
16
|
+
SecureRandom.uuid
|
17
|
+
end
|
18
|
+
|
13
19
|
class App < Sinatra::Base
|
14
20
|
set :root, File.expand_path("../../app", __FILE__)
|
15
21
|
set :public_folder do "#{root}/assets" end
|
@@ -22,11 +28,31 @@ module Tailog
|
|
22
28
|
end
|
23
29
|
|
24
30
|
get '/' do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
31
|
+
redirect to('/logs')
|
32
|
+
end
|
33
|
+
|
34
|
+
get '/logs' do
|
35
|
+
erb :'logs/index'
|
36
|
+
end
|
37
|
+
|
38
|
+
post '/logs' do
|
39
|
+
begin
|
40
|
+
file_path = File.join Tailog.log_path, params[:file]
|
41
|
+
file = File.open file_path
|
42
|
+
file_size = file.size
|
43
|
+
seek = params[:seek] && params[:seek][Tailog.server_uuid] || file_size
|
44
|
+
file.seek seek.to_i
|
45
|
+
content = erb :'logs/list', locals: { file: file }
|
46
|
+
file.close
|
47
|
+
rescue => error
|
48
|
+
content = erb :error, locals: { error: error }
|
29
49
|
end
|
50
|
+
|
51
|
+
{
|
52
|
+
server_uuid: Tailog.server_uuid,
|
53
|
+
file_size: file_size,
|
54
|
+
content: content
|
55
|
+
}.to_json
|
30
56
|
end
|
31
57
|
end
|
32
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tailog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bbtfr
|
@@ -50,8 +50,9 @@ files:
|
|
50
50
|
- Gemfile
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
|
-
- app/views/
|
54
|
-
- app/views/index.erb
|
53
|
+
- app/views/error.erb
|
54
|
+
- app/views/logs/index.erb
|
55
|
+
- app/views/logs/list.erb
|
55
56
|
- bin/console
|
56
57
|
- bin/setup
|
57
58
|
- lib/tailog.rb
|
data/app/views/ajax.erb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
<% begin %>
|
2
|
-
<% file_path = File.join Tailog.log_path, params[:file] %>
|
3
|
-
<% File.open file_path do |file| %>
|
4
|
-
<% file_size = file.size %>
|
5
|
-
<% file.seek params[:seek].to_i %>
|
6
|
-
<% file.each_line do |line| %>
|
7
|
-
<p><%= h line %></p>
|
8
|
-
<% end %>
|
9
|
-
<script type="text/javascript">
|
10
|
-
if (window.fileSize < <%= file_size %>)
|
11
|
-
window.fileSize = <%= file_size %>;
|
12
|
-
</script>
|
13
|
-
<% end %>
|
14
|
-
<% rescue => error %>
|
15
|
-
<div class="alert alert-danger">
|
16
|
-
<h4><%= h error.class %>: <%= h error.message %></h4>
|
17
|
-
<% error.backtrace.each do |backtrace| %>
|
18
|
-
<%= h backtrace %><br>
|
19
|
-
<% end %>
|
20
|
-
</div>
|
21
|
-
<% end %>
|