localtower 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/controllers/localtower/pages_controller.rb +17 -0
- data/app/views/localtower/pages/logs.html.erb +42 -28
- data/config/routes.rb +2 -0
- data/lib/localtower/plugins/capture.rb +73 -44
- data/lib/localtower/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98aac578fc2ae63c3eb8ead3984e40552358eb70
|
4
|
+
data.tar.gz: 9d37649aa3aad2e7f5e5bd98f97896a50fb873d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6a760895312eebaf0da5545abe5750b64de83211766f174ea4ea219e57fcbd9fb1a0ba2650f5f8474907288d0883e232949de55734dc09ae4e25281620e7b4b
|
7
|
+
data.tar.gz: bf53f8dda0685922284843e043cf13d1fadd91b59a88305eb34fd3c9233b0a109a8bef3a75ac56d968fb61f953896f655ef706ec356df3f4e30e835b1d08b5ca
|
data/README.md
CHANGED
@@ -10,6 +10,23 @@ module Localtower
|
|
10
10
|
@logs = Localtower::Plugins::Capture.new.logs
|
11
11
|
end
|
12
12
|
|
13
|
+
def log
|
14
|
+
file = Dir["#{Localtower::Plugins::Capture::LOG_PATH.call}/localtower*#{params[:md5]}*"][0]
|
15
|
+
|
16
|
+
render json: JSON.parse(open(file).read)
|
17
|
+
end
|
18
|
+
|
19
|
+
def log_var
|
20
|
+
answer = {}
|
21
|
+
|
22
|
+
file = Dir["#{Localtower::Plugins::Capture::LOG_PATH.call}/localtower*#{params[:md5]}*"][0]
|
23
|
+
data = JSON.parse(open(file).read)
|
24
|
+
|
25
|
+
answer = data["variables"].select {|i| i["event_name"] == params[:var] }[0]["returned"]
|
26
|
+
|
27
|
+
render json: answer
|
28
|
+
end
|
29
|
+
|
13
30
|
def status
|
14
31
|
@data = ::Localtower::Status.new.run
|
15
32
|
end
|
@@ -14,53 +14,67 @@
|
|
14
14
|
border: 1px solid #cacaca;
|
15
15
|
line-height: 1.2em;
|
16
16
|
overflow:auto;
|
17
|
+
max-height: 800px;
|
18
|
+
max-width: 800px;
|
17
19
|
-moz-background-clip: padding;
|
18
20
|
-webkit-background-clip: padding-box;
|
19
21
|
background-clip: padding-box;
|
20
22
|
background-color: #FAFAFB;
|
21
23
|
color: #393939;
|
22
24
|
margin: 0px;
|
23
|
-
max-width: 800px;
|
24
25
|
display: block;
|
25
26
|
}
|
26
|
-
|
27
27
|
</style>
|
28
|
-
|
29
|
-
|
30
|
-
|
31
28
|
<% content_for :title do %>Logs<% end %>
|
32
|
-
|
33
29
|
<div class="row">
|
34
30
|
<div class="col-md-12">
|
35
31
|
<div class="card">
|
36
32
|
<div class="header">
|
37
|
-
<h4 class="title"
|
33
|
+
<h4 class="title">
|
34
|
+
<pre>Localtower::Plugins::Capture.new(self, binding).save</pre>
|
35
|
+
</h4>
|
38
36
|
</div>
|
39
|
-
|
40
37
|
<div class="content">
|
41
38
|
<table class="table">
|
42
39
|
<thead>
|
43
|
-
<th>
|
44
|
-
<th>
|
45
|
-
<th>
|
40
|
+
<th>TYPE</th>
|
41
|
+
<th>IN CLASS</th>
|
42
|
+
<th>IN METHOD</th>
|
43
|
+
<th>VARIABLE</th>
|
44
|
+
<th>VALUE</th>
|
46
45
|
</thead>
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
46
|
+
<tbody>
|
47
|
+
<% @logs.each do |log| %>
|
48
|
+
<% log["variables"].each do |item| %>
|
49
|
+
<tr>
|
50
|
+
<td>
|
51
|
+
<span class="label label-success">
|
52
|
+
<%= item["type"] %>
|
53
|
+
</span>
|
54
|
+
</td>
|
55
|
+
<td>
|
56
|
+
<span>
|
57
|
+
<a class="code" href="subl://open/?url=file://<%= item["meta"]["sublime_path"] %>">
|
58
|
+
<%= item["meta"]["from_klass"] %>
|
59
|
+
</a>
|
60
|
+
</span>
|
61
|
+
</td>
|
62
|
+
<td>
|
63
|
+
<span class="code">
|
64
|
+
<%= item["meta"]["from_method"] %>
|
65
|
+
</span>
|
66
|
+
</td>
|
67
|
+
<td>
|
68
|
+
<span class="code">
|
69
|
+
<%= item["event_name"] %>
|
70
|
+
</span>
|
71
|
+
</td>
|
72
|
+
<td>
|
73
|
+
<a href="<%= log_var_path(log["md5"], item["event_name"]) %>">open</a>
|
74
|
+
<pre class="value json code"><%= Localtower::Plugins::Capture.printable(item["returned"]) %></pre>
|
75
|
+
</td>
|
76
|
+
</tr>
|
77
|
+
<% end %>
|
64
78
|
<% end %>
|
65
79
|
</tbody>
|
66
80
|
</table>
|
data/config/routes.rb
CHANGED
@@ -13,6 +13,8 @@ Localtower::Engine.routes.draw do
|
|
13
13
|
|
14
14
|
get 'dashboard', to: 'pages#dashboard', as: 'dashboard'
|
15
15
|
get 'logs', to: 'pages#logs', as: 'logs'
|
16
|
+
get 'logs/:md5', to: 'pages#log', as: 'log'
|
17
|
+
get 'logs/:md5/:var', to: 'pages#log_var', as: 'log_var'
|
16
18
|
|
17
19
|
root :to => redirect('dashboard')
|
18
20
|
end
|
@@ -2,6 +2,7 @@ module Localtower
|
|
2
2
|
module Plugins
|
3
3
|
class Capture
|
4
4
|
LOG_FILE = lambda { "#{Rails.root}/log/localtower_capture.log" }
|
5
|
+
LOG_PATH = lambda { "#{Rails.root}/log" }
|
5
6
|
EXCLUDE_INSTANCE_VARIABLES = [
|
6
7
|
"@_action_has_layout",
|
7
8
|
"@_routes",
|
@@ -47,15 +48,14 @@ module Localtower
|
|
47
48
|
end
|
48
49
|
|
49
50
|
def logs
|
50
|
-
|
51
|
-
content = File.open(LOG_FILE.call).read
|
52
|
-
else
|
53
|
-
content = nil
|
54
|
-
end
|
51
|
+
list = []
|
55
52
|
|
56
|
-
|
53
|
+
Dir["#{LOG_PATH.call}/localtower_capture_*.json"].each do |file|
|
54
|
+
json = JSON.parse(open(file).read)
|
55
|
+
list << json
|
56
|
+
end
|
57
57
|
|
58
|
-
|
58
|
+
list
|
59
59
|
end
|
60
60
|
|
61
61
|
def my_logger
|
@@ -70,16 +70,24 @@ module Localtower
|
|
70
70
|
def values
|
71
71
|
hash = {}
|
72
72
|
|
73
|
-
|
73
|
+
callers = @context.send(:caller)
|
74
|
+
a = callers[1] # xx/xx/app/controllers/clients/events_controller.rb:57:in `new'
|
74
75
|
a = a.split(Rails.root.to_s).last # events_controller.rb:57:in `new'
|
75
76
|
a = a.split("\:")
|
76
77
|
|
78
|
+
|
77
79
|
file = a[0].strip
|
78
80
|
line_number = a[1].strip
|
79
81
|
method = a[2].strip.gsub("in \`", "").gsub("\'", "")
|
80
82
|
|
83
|
+
sublime_path = "#{callers[1].split(":")[0]}:#{line_number}"
|
84
|
+
|
81
85
|
hash["class"] = self.klass_name
|
82
|
-
hash["
|
86
|
+
hash["file"] = "#{file}##{method}:#{line_number}"
|
87
|
+
hash["method"] = method
|
88
|
+
hash["md5"] = Digest::MD5.hexdigest(hash["file"])
|
89
|
+
hash["type"] = "CAPTURE_METHOD"
|
90
|
+
hash["time"] = Time.now.utc.strftime('%Y-%m-%d %H:%M:%S.%L')
|
83
91
|
|
84
92
|
variables = []
|
85
93
|
|
@@ -89,19 +97,28 @@ module Localtower
|
|
89
97
|
value = @context_binding.local_variable_get(var)
|
90
98
|
klass = self.class.type_of(value)
|
91
99
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
100
|
+
data = {
|
101
|
+
type: 'CAPTURE',
|
102
|
+
time: Time.now.utc.strftime('%Y-%m-%d %H:%M:%S.%L'),
|
103
|
+
event_name: var,
|
104
|
+
identifier: nil,
|
105
|
+
returned: value,
|
106
|
+
meta: {
|
107
|
+
from_klass: hash["class"],
|
108
|
+
from_method: hash["method"],
|
109
|
+
klass: klass.to_s,
|
110
|
+
method: method.to_s,
|
111
|
+
# arguments: data[:arguments],
|
112
|
+
callers: callers,
|
113
|
+
# table_name: data[:table_name],
|
114
|
+
# sql: data[:sql],
|
115
|
+
sublime_path: sublime_path,
|
116
|
+
file: hash["file"],
|
117
|
+
line: line_number
|
118
|
+
}
|
96
119
|
}
|
97
120
|
|
98
|
-
|
99
|
-
variables << {
|
100
|
-
name: "#{var}_count",
|
101
|
-
value: value.count,
|
102
|
-
klass: nil
|
103
|
-
}
|
104
|
-
end
|
121
|
+
variables << data
|
105
122
|
end
|
106
123
|
|
107
124
|
@context.instance_variables.each do |var|
|
@@ -110,19 +127,36 @@ module Localtower
|
|
110
127
|
value = @context.instance_variable_get(var.to_sym)
|
111
128
|
klass = self.class.type_of(value)
|
112
129
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
130
|
+
data = {
|
131
|
+
type: 'CAPTURE',
|
132
|
+
time: Time.now.utc.strftime('%Y-%m-%d %H:%M:%S.%L'),
|
133
|
+
event_name: var,
|
134
|
+
identifier: nil,
|
135
|
+
returned: value,
|
136
|
+
meta: {
|
137
|
+
from_klass: hash["class"],
|
138
|
+
from_method: hash["method"],
|
139
|
+
klass: klass.to_s,
|
140
|
+
method: method.to_s,
|
141
|
+
# arguments: data[:arguments],
|
142
|
+
callers: callers,
|
143
|
+
# table_name: data[:table_name],
|
144
|
+
# sql: data[:sql],
|
145
|
+
sublime_path: sublime_path,
|
146
|
+
file: hash["file"],
|
147
|
+
line: line_number
|
148
|
+
}
|
117
149
|
}
|
118
150
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
151
|
+
variables << data
|
152
|
+
|
153
|
+
# if value.is_a?(ActiveRecord::AssociationRelation) and value.respond_to?(:count)
|
154
|
+
# variables << {
|
155
|
+
# name: "#{var}_count",
|
156
|
+
# value: value.count,
|
157
|
+
# klass: nil
|
158
|
+
# }
|
159
|
+
# end
|
126
160
|
end
|
127
161
|
|
128
162
|
hash["variables"] = variables
|
@@ -140,28 +174,23 @@ module Localtower
|
|
140
174
|
value.to_s
|
141
175
|
end
|
142
176
|
|
143
|
-
|
144
|
-
|
145
|
-
|
177
|
+
def clear
|
178
|
+
Dir["#{LOG_PATH.call}/localtower_capture_*.json"].each do |file|
|
179
|
+
File.delete(file)
|
180
|
+
end
|
146
181
|
|
147
|
-
|
148
|
-
# Clear the logs
|
149
|
-
File.open(LOG_FILE.call, 'w') { |f| f.write("{}") }
|
182
|
+
self
|
150
183
|
end
|
151
184
|
|
152
185
|
def save
|
153
186
|
return nil if Rails.env.production?
|
154
|
-
|
155
|
-
self.init
|
187
|
+
self.clear
|
156
188
|
|
157
189
|
data = self.values
|
158
|
-
data.each do |value|
|
159
|
-
puts value
|
160
|
-
end
|
161
|
-
|
162
190
|
json = data.to_json
|
191
|
+
file = "#{LOG_PATH.call}/localtower_capture_#{data['md5']}.json"
|
163
192
|
|
164
|
-
File.open(
|
193
|
+
File.open(file, 'w') { |f| f.write(json) }
|
165
194
|
# log "#{json}\n"
|
166
195
|
end
|
167
196
|
|
data/lib/localtower/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: localtower
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damian Le Nouaille
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|