tailog 0.2.3 → 0.3.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/env.erb +1 -1
- data/app/views/layout.erb +19 -11
- data/app/views/logs/index.erb +3 -3
- data/app/views/script/bash.erb +23 -0
- data/app/views/script/index.erb +29 -0
- data/app/views/script/ruby.erb +16 -0
- data/lib/tailog/version.rb +1 -1
- data/lib/tailog/watch_methods.rb +63 -0
- data/lib/tailog.rb +18 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c991598a6429b679173bc6cbbc0ca3ebc715cc1a
|
4
|
+
data.tar.gz: 4fdacb9590e666904a46bd87eda40a6e10023ca5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 505f2991c831834238d6706d144a0cdef0ebcf4e5aee40fa7114ae33ce3af366963cb15c0baa1ab73eee6608873b38e32c700f4418010ed3a70fd3524d97c0cd
|
7
|
+
data.tar.gz: 0ab82aeda9b8222c09323590365382edc11a83937c7a86453e09f046ad7188277c80f76380a7e011ab58fcd50a90ffe44ba0792dbf554f8e3c2a3b142095b0fd
|
data/app/views/env.erb
CHANGED
data/app/views/layout.erb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
<head>
|
4
4
|
<title>TAILOG</title>
|
5
5
|
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
|
6
|
+
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/3.51/jquery.form.js"></script>
|
6
7
|
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css">
|
7
8
|
<style type="text/css">
|
8
9
|
body {
|
@@ -16,12 +17,26 @@
|
|
16
17
|
margin: 0;
|
17
18
|
}
|
18
19
|
|
19
|
-
p:hover {
|
20
|
+
.content-hover p:hover {
|
20
21
|
background: #EEE;
|
21
22
|
}
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
.dl-horizontal dt {
|
25
|
+
width: 320px;
|
26
|
+
padding-right: 20px;
|
27
|
+
}
|
28
|
+
|
29
|
+
.dl-horizontal dd {
|
30
|
+
margin-left: 320px;
|
31
|
+
}
|
32
|
+
|
33
|
+
.dl-hover dt:hover + dd, .dl-hover dd:hover {
|
34
|
+
background: #EEE;
|
35
|
+
}
|
36
|
+
|
37
|
+
.script select.form-control {
|
38
|
+
display: inline-block;
|
39
|
+
width: 100px;
|
25
40
|
}
|
26
41
|
</style>
|
27
42
|
</head>
|
@@ -40,16 +55,9 @@
|
|
40
55
|
<ul class="nav navbar-nav">
|
41
56
|
<li<%= ' class="active"' if path_info == "/logs" %>><a href="logs">Logs</a></li>
|
42
57
|
<li<%= ' class="active"' if path_info == "/env" %>><a href="env">Env</a></li>
|
58
|
+
<li<%= ' class="active"' if path_info == "/script" %>><a href="script">Script</a></li>
|
43
59
|
</ul>
|
44
60
|
<ul class="nav navbar-nav navbar-right">
|
45
|
-
<form class="navbar-form navbar-left" method="get">
|
46
|
-
<div class="input-group">
|
47
|
-
<input name="file" type="text" class="form-control" placeholder="<%= params[:file] || 'File Name...' %>">
|
48
|
-
<span class="input-group-btn">
|
49
|
-
<button class="btn btn-default" type="button">Go!</button>
|
50
|
-
</span>
|
51
|
-
</div>
|
52
|
-
</form>
|
53
61
|
</ul>
|
54
62
|
</div><!--/.nav-collapse -->
|
55
63
|
</div><!--/.container-fluid -->
|
data/app/views/logs/index.erb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
<h3 class="page-header"><%= file_path %></h3>
|
8
8
|
|
9
9
|
<% File.open file_path do |file| %>
|
10
|
-
<div id="content"></div>
|
10
|
+
<div id="content" class="content-hover"></div>
|
11
11
|
<% end %>
|
12
12
|
|
13
13
|
<script type="text/javascript">
|
@@ -30,7 +30,7 @@
|
|
30
30
|
if (!data.content) return;
|
31
31
|
var shouldScrollToBottom = $window.scrollTop() + $window.height() == $document.height();
|
32
32
|
$content
|
33
|
-
.append('<
|
33
|
+
.append('<span class="text-info">' + data.server_uuid + '</span>')
|
34
34
|
.append(data.content);
|
35
35
|
|
36
36
|
if (shouldScrollToBottom) {
|
@@ -50,7 +50,7 @@
|
|
50
50
|
<% else %>
|
51
51
|
<% Dir[File.join Tailog.log_path, '**/*.log'].each do |file| %>
|
52
52
|
<% relative_file = Pathname.new(file).relative_path_from(Pathname.new(Tailog.log_path)) %>
|
53
|
-
<a href="?file=<%= relative_file %>"><%= file %></a>
|
53
|
+
<p><a href="?file=<%= relative_file %>"><%= file %></a></p>
|
54
54
|
<% end %>
|
55
55
|
<% end %>
|
56
56
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<% begin %>
|
2
|
+
<% Open3.popen3("bash -x -e") do |stdin, stdout, stderr, wait_thr| %>
|
3
|
+
<% output = [] %>
|
4
|
+
<% Thread.new do until (line = stdout.gets).nil? do output << [ :stdout, line ] end end %>
|
5
|
+
<% Thread.new do until (line = stderr.gets).nil? do output << [ :stderr, line ] end end %>
|
6
|
+
|
7
|
+
<% stdin.puts script %>
|
8
|
+
<% stdin.puts "exit" %>
|
9
|
+
<% wait_thr.join %>
|
10
|
+
|
11
|
+
<% output.each do |key, line| %>
|
12
|
+
<% if key == :stdout %>
|
13
|
+
<p><%= h line %></p>
|
14
|
+
<% elsif line =~ /^\+ (.*)/ %>
|
15
|
+
<p class="text-info">$ <%= h $1 %></p>
|
16
|
+
<% else %>
|
17
|
+
<p class="text-danger"><%= h line %></p>
|
18
|
+
<% end %>
|
19
|
+
<% end %>
|
20
|
+
<% end %>
|
21
|
+
<% rescue => error %>
|
22
|
+
<%= erb :error, locals: { error: error }, layout: false %>
|
23
|
+
<% end %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<form id="script" class="clearfix script" method="post">
|
2
|
+
<div class="form-group">
|
3
|
+
<textarea name="script" class="form-control" placeholder="Your Script..." rows="8"></textarea>
|
4
|
+
</div>
|
5
|
+
<div class="pull-right">
|
6
|
+
<select name="type" class="form-control">
|
7
|
+
<option value="ruby">Ruby</option>
|
8
|
+
<option value="bash">Bash</option>
|
9
|
+
</select>
|
10
|
+
<button type="submit" class="btn btn-primary">Submit</button>
|
11
|
+
</div>
|
12
|
+
</form>
|
13
|
+
|
14
|
+
<div id="content"></div>
|
15
|
+
|
16
|
+
<script type="text/javascript">
|
17
|
+
var $content = $("#content");
|
18
|
+
|
19
|
+
$('#script').ajaxForm(function(json) {
|
20
|
+
try {
|
21
|
+
var data = JSON.parse(json);
|
22
|
+
$content
|
23
|
+
.html('<hr>')
|
24
|
+
.append(data.content);
|
25
|
+
} catch (error) {
|
26
|
+
console.log(error)
|
27
|
+
}
|
28
|
+
});
|
29
|
+
</script>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<% begin %>
|
2
|
+
<% b = binding %>
|
3
|
+
<% script.each_line do |line| %>
|
4
|
+
<% next if line.strip.empty? %>
|
5
|
+
<p class="text-info">> <%= h line %></p>
|
6
|
+
<% begin %>
|
7
|
+
<% result = b.eval(line).inspect %>
|
8
|
+
<p>=> <%= h result %></p>
|
9
|
+
<% rescue => error %>
|
10
|
+
<p class="text-danger"><%= h error.class %>: <%= h error.message %></p>
|
11
|
+
<% break %>
|
12
|
+
<% end %>
|
13
|
+
<% end %>
|
14
|
+
<% rescue => error %>
|
15
|
+
<%= erb :error, locals: { error: error }, layout: false %>
|
16
|
+
<% end %>
|
data/lib/tailog/version.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'active_support/core_ext/string'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
module Tailog
|
5
|
+
module WatchMethods
|
6
|
+
def self.logger
|
7
|
+
@logger ||= Logger.new(File.join Tailog.log_path, "watch_methods.log")
|
8
|
+
end
|
9
|
+
|
10
|
+
def inject_methods targets
|
11
|
+
targets.each do |target|
|
12
|
+
if target.include? "#"
|
13
|
+
inject_instance_method target
|
14
|
+
else
|
15
|
+
inject_class_method target
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def inject_class_method target
|
23
|
+
klass, _, method = if target.include? "."
|
24
|
+
target.rpartition(".")
|
25
|
+
else
|
26
|
+
target.rpartition("::")
|
27
|
+
end
|
28
|
+
klass.constantize.class_eval <<-EOS, __FILE__, __LINE__
|
29
|
+
class << self
|
30
|
+
#{build_watch_method target, method}
|
31
|
+
end
|
32
|
+
EOS
|
33
|
+
rescue => error
|
34
|
+
WatchMethods.logger.error "Inject class method `#{target}' failed: #{error.class}: #{error.message}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def inject_instance_method target
|
38
|
+
klass, _, method = target.rpartition("#")
|
39
|
+
klass.constantize.class_eval <<-EOS, __FILE__, __LINE__
|
40
|
+
#{build_watch_method target, method}
|
41
|
+
EOS
|
42
|
+
rescue => error
|
43
|
+
WatchMethods.logger.error "Inject instance method `#{target}' failed: #{error.class}: #{error.message}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_watch_method target, method
|
47
|
+
raw_method = "watch_method_raw_#{method}"
|
48
|
+
return <<-EOS
|
49
|
+
alias_method :#{raw_method}, :#{method}
|
50
|
+
def #{method} *args
|
51
|
+
Tailog::WatchMethods.logger.info "Method called: #{target} with \#{args}"
|
52
|
+
start = Time.now
|
53
|
+
result = send :#{raw_method}, *args
|
54
|
+
Tailog::WatchMethods.logger.info "Method finished: #{target} with \#{result} in \#{(Time.now - start) * 1000} ms"
|
55
|
+
result
|
56
|
+
rescue => error
|
57
|
+
Tailog::WatchMethods.logger.error "Method failed: #{target} raises \#{error.class}: \#{error.message}\\n\#{error.backtrace.join("\\n")}"
|
58
|
+
raise error
|
59
|
+
end
|
60
|
+
EOS
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/tailog.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
require 'tailog/version'
|
2
|
+
require 'tailog/watch_methods'
|
3
|
+
require 'tailog/ext/file'
|
4
|
+
|
2
5
|
require 'sinatra/base'
|
3
6
|
require 'active_support/configurable'
|
4
|
-
|
7
|
+
|
5
8
|
require 'securerandom'
|
9
|
+
require 'open3'
|
6
10
|
require 'json'
|
7
11
|
|
8
12
|
module Tailog
|
9
13
|
include ActiveSupport::Configurable
|
14
|
+
extend Tailog::WatchMethods
|
10
15
|
|
11
16
|
config_accessor :log_path do
|
12
17
|
File.expand_path("log", Dir.pwd)
|
@@ -62,5 +67,17 @@ module Tailog
|
|
62
67
|
get '/env' do
|
63
68
|
erb :env
|
64
69
|
end
|
70
|
+
|
71
|
+
get '/script' do
|
72
|
+
erb :'script/index'
|
73
|
+
end
|
74
|
+
|
75
|
+
post '/script' do
|
76
|
+
content = erb :"script/#{params[:type]}", locals: { script: params[:script] }, layout: false
|
77
|
+
|
78
|
+
{
|
79
|
+
content: content
|
80
|
+
}.to_json
|
81
|
+
end
|
65
82
|
end
|
66
83
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tailog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bbtfr
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,11 +55,15 @@ files:
|
|
55
55
|
- app/views/layout.erb
|
56
56
|
- app/views/logs/index.erb
|
57
57
|
- app/views/logs/list.erb
|
58
|
+
- app/views/script/bash.erb
|
59
|
+
- app/views/script/index.erb
|
60
|
+
- app/views/script/ruby.erb
|
58
61
|
- bin/console
|
59
62
|
- bin/setup
|
60
63
|
- lib/tailog.rb
|
61
64
|
- lib/tailog/ext/file.rb
|
62
65
|
- lib/tailog/version.rb
|
66
|
+
- lib/tailog/watch_methods.rb
|
63
67
|
- tailog.gemspec
|
64
68
|
homepage: https://github.com/bbtfr/tailog
|
65
69
|
licenses: []
|