tailog 0.3.1 → 0.3.2
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/layout.erb +1 -1
- data/app/views/logs/index.erb +3 -3
- data/app/views/script/index.erb +1 -0
- data/lib/tailog/version.rb +1 -1
- data/lib/tailog/watch_methods.rb +22 -18
- data/lib/tailog.rb +8 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e883f46101f9d9932bd47c8d275fc4c304a7026
|
4
|
+
data.tar.gz: 6ca0aa4bfc2d1806f386465153607b24d7a18683
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a3741b98e3cf6b9bed879a6e66c12678d75c2bf3a61db9667724851d44a76186209080166d84866212770a3103f427ec0d134e98f42af0565cfa5a37a4ddb87
|
7
|
+
data.tar.gz: 3fcc682690a3242219f6af6939e2b5d3a174cc0f352f2f387810be6907a87afa04d68f9cd3db916e4cb99cfb0a78700d9769d24c8b400e9c11c02bc2d60386bb
|
data/app/views/layout.erb
CHANGED
data/app/views/logs/index.erb
CHANGED
@@ -22,15 +22,15 @@
|
|
22
22
|
try {
|
23
23
|
var data = JSON.parse(json);
|
24
24
|
|
25
|
-
var fileSizeKey = data.
|
25
|
+
var fileSizeKey = data.server_hostname + '-' + data.file_size;
|
26
26
|
if (window.fileSizeDone[fileSizeKey]) return;
|
27
27
|
window.fileSizeDone[fileSizeKey] = true;
|
28
|
-
window.fileSize[data.
|
28
|
+
window.fileSize[data.server_hostname] = data.file_size;
|
29
29
|
|
30
30
|
if (!data.content) return;
|
31
31
|
var shouldScrollToBottom = $window.scrollTop() + $window.height() == $document.height();
|
32
32
|
$content
|
33
|
-
.append('<span class="text-info">' + data.
|
33
|
+
.append('<span class="text-info">' + data.server_hostname + '</span>')
|
34
34
|
.append(data.content);
|
35
35
|
|
36
36
|
if (shouldScrollToBottom) {
|
data/app/views/script/index.erb
CHANGED
data/lib/tailog/version.rb
CHANGED
data/lib/tailog/watch_methods.rb
CHANGED
@@ -9,10 +9,14 @@ module Tailog
|
|
9
9
|
|
10
10
|
def inject_methods targets
|
11
11
|
targets.each do |target|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
begin
|
13
|
+
if target.include? "#"
|
14
|
+
inject_instance_method target
|
15
|
+
else
|
16
|
+
inject_class_method target
|
17
|
+
end
|
18
|
+
rescue => error
|
19
|
+
WatchMethods.logger.error "Inject method `#{target}' failed: #{error.class}: #{error.message}"
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
@@ -30,8 +34,6 @@ module Tailog
|
|
30
34
|
#{build_watch_method target, method}
|
31
35
|
end
|
32
36
|
EOS
|
33
|
-
rescue => error
|
34
|
-
WatchMethods.logger.error "Inject class method `#{target}' failed: #{error.class}: #{error.message}"
|
35
37
|
end
|
36
38
|
|
37
39
|
def inject_instance_method target
|
@@ -39,23 +41,25 @@ module Tailog
|
|
39
41
|
klass.constantize.class_eval <<-EOS, __FILE__, __LINE__
|
40
42
|
#{build_watch_method target, method}
|
41
43
|
EOS
|
42
|
-
rescue => error
|
43
|
-
WatchMethods.logger.error "Inject instance method `#{target}' failed: #{error.class}: #{error.message}"
|
44
44
|
end
|
45
45
|
|
46
46
|
def build_watch_method target, method
|
47
47
|
raw_method = "watch_method_raw_#{method}"
|
48
48
|
return <<-EOS
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
49
|
+
unless instance_methods.include?(:#{raw_method})
|
50
|
+
alias_method :#{raw_method}, :#{method}
|
51
|
+
def #{method} *args
|
52
|
+
Tailog::WatchMethods.logger.info "Method called: #{target}, self: \#{self.inspect}, arguments: \#{args.inspect}"
|
53
|
+
start = Time.now
|
54
|
+
result = send :#{raw_method}, *args
|
55
|
+
Tailog::WatchMethods.logger.info "Method finished: #{target} in \#{(Time.now - start) * 1000} ms, result: \#{result.inspect}"
|
56
|
+
result
|
57
|
+
rescue => error
|
58
|
+
Tailog::WatchMethods.logger.error "Method failed: #{target}, error: \#{error.class} - \#{error.message}\\n\#{error.backtrace.join("\\n")}"
|
59
|
+
raise error
|
60
|
+
end
|
61
|
+
else
|
62
|
+
Tailog::WatchMethods.logger.error "Inject method `#{target}' failed: already injected"
|
59
63
|
end
|
60
64
|
EOS
|
61
65
|
end
|
data/lib/tailog.rb
CHANGED
@@ -5,7 +5,7 @@ require 'tailog/ext/file'
|
|
5
5
|
require 'sinatra/base'
|
6
6
|
require 'active_support/configurable'
|
7
7
|
|
8
|
-
require '
|
8
|
+
require 'socket'
|
9
9
|
require 'open3'
|
10
10
|
require 'json'
|
11
11
|
|
@@ -13,13 +13,11 @@ module Tailog
|
|
13
13
|
include ActiveSupport::Configurable
|
14
14
|
extend Tailog::WatchMethods
|
15
15
|
|
16
|
-
config_accessor :log_path
|
17
|
-
|
18
|
-
end
|
16
|
+
config_accessor :log_path
|
17
|
+
self.log_path = File.expand_path("log", Dir.pwd)
|
19
18
|
|
20
|
-
config_accessor :
|
21
|
-
|
22
|
-
end
|
19
|
+
config_accessor :server_hostname
|
20
|
+
self.server_hostname = Socket.gethostname
|
23
21
|
|
24
22
|
class App < Sinatra::Base
|
25
23
|
set :root, File.expand_path("../../app", __FILE__)
|
@@ -45,7 +43,7 @@ module Tailog
|
|
45
43
|
file_path = File.join Tailog.log_path, params[:file]
|
46
44
|
file = File.open file_path
|
47
45
|
file_size = file.size
|
48
|
-
tail = if seek = params[:seek] && params[:seek][Tailog.
|
46
|
+
tail = if seek = params[:seek] && params[:seek][Tailog.server_hostname]
|
49
47
|
file.seek seek.to_i
|
50
48
|
file
|
51
49
|
else
|
@@ -58,7 +56,7 @@ module Tailog
|
|
58
56
|
end
|
59
57
|
|
60
58
|
{
|
61
|
-
|
59
|
+
server_hostname: Tailog.server_hostname,
|
62
60
|
file_size: file_size,
|
63
61
|
content: content
|
64
62
|
}.to_json
|
@@ -76,6 +74,7 @@ module Tailog
|
|
76
74
|
content = erb :"script/#{params[:type]}", locals: { script: params[:script] }, layout: false
|
77
75
|
|
78
76
|
{
|
77
|
+
server_hostname: Tailog.server_hostname,
|
79
78
|
content: content
|
80
79
|
}.to_json
|
81
80
|
end
|