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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a96a77ac5c624154a347d958d89ec3646b025c4
4
- data.tar.gz: c1fe7e1ee366f1c633890c8de1c575f6146ef533
3
+ metadata.gz: 94898f11ab8489deacbdd01e07f902ac201740f3
4
+ data.tar.gz: 4d42e7d30f37d856c349e3ffadc5a91d070fde1e
5
5
  SHA512:
6
- metadata.gz: cdc93b392d1fa36f91c97ec62b4403e117bdf49c49ad0f86ac71953835aa65ee33bd7657a7c92b625643f26fee74fc0a926e7b9b9935221fe954199864e656ce
7
- data.tar.gz: 146f2c87a92bd07da1fd1f228ed34279174c2fcd5681c1651ae9ecb8a732a3c1dc1893eb08a798b55e898b131ae0fc0d44b2b2c7db0bc8d13c97bf78099d21de
6
+ metadata.gz: 7c0ceab245395356fbc3ba8be2e8c7ef943814e54dcafbde612c496a4dd5b6d8069fe0acaca37cc3e44bbb84fc92952e625b18c0e313aa7751ba305917fce8f2
7
+ data.tar.gz: 90be1575fd13c56462793d667298f880ecf1c3334af0a4374b908a654642971957e14ff63f5cc5c1d39030a404cced5ba38d46ce877b3951b6dbd3d5df0e98c1
@@ -0,0 +1,6 @@
1
+ <div class="alert alert-danger monospace">
2
+ <h4><%= h error.class %>: <%= h error.message %></h4>
3
+ <% error.backtrace.each do |backtrace| %>
4
+ <%= h backtrace %><br>
5
+ <% end %>
6
+ </div>
@@ -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
- <div id="content" class="monospace">
70
- <% file_size = file.size %>
71
- <% file.tail(100).each do |line| %>
72
- <p><%= h line %></p>
73
- <% end %>
74
- </div>
75
-
76
- <script type="text/javascript">
77
- window.fileSize = <%= file_size %>;
78
- window.fileSizeDone = {};
79
- var $window = $(window),
80
- $document = $(document),
81
- $content = $("#content");
82
-
83
- setInterval(function() {
84
- $.get(window.location.href, { seek: window.fileSize }, function(data) {
85
- var $data = $(data);
86
-
87
- if (window.fileSizeDone[window.fileSize]) {
88
- return
89
- } else if (!$data.length) {
90
- window.fileSizeDone[window.fileSize] = true
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
- if ($window.scrollTop() + $window.height() == $document.height()) {
94
- $(data).appendTo($content);
95
- $window.scrollTop($document.height() - $window.height())
96
- } else {
97
- $(data).appendTo($content);
98
- }
99
- });
100
- }, 3000);
101
- </script>
95
+ } catch (error) {
96
+ console.log(error)
97
+ }
98
+ });
99
+ }
102
100
 
103
- <% end %>
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
- <div class="alert alert-danger">
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 -->
@@ -0,0 +1,3 @@
1
+ <% file.each_line do |line| %>
2
+ <p><%= h line %></p>
3
+ <% end %>
@@ -1,3 +1,3 @@
1
1
  module Tailog
2
- VERSION = "0.1.6"
2
+ VERSION = "0.2.0"
3
3
  end
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
- if params[:seek]
26
- erb :ajax
27
- else
28
- erb :index
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.1.6
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/ajax.erb
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 %>