caller_log 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/caller_log.gemspec +0 -1
- data/lib/caller_log.rb +31 -9
- data/lib/caller_log/log.rb +4 -2
- data/lib/caller_log/template.html +25 -3
- data/lib/caller_log/version.rb +1 -1
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dce8296b1ca697f272b3dae5e064f8899d64cecb
|
4
|
+
data.tar.gz: 44c6a29b8c78d936864511c9e6695a95b0b0f06c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9768b0ee6e4019c3670b70811e0053193865439f150c17cc756933969d4e919d66ab05e950f3a3d48f4a574e909ae0470207ccdf5c3690591ab77fe8c08ccace
|
7
|
+
data.tar.gz: 5b1718a7b4075dd31c857b3eb3101d5af8e1231799f877b9d432e8abddb8aeef92f3de94a445a0c384c415af260be66c57539ba62ca4693f3be9df9f852bf734
|
data/caller_log.gemspec
CHANGED
@@ -24,7 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
spec.add_development_dependency "minitest", "~> 5.0"
|
26
26
|
|
27
|
-
spec.add_dependency "dcr"
|
28
27
|
spec.add_dependency "binding_of_callers"
|
29
28
|
spec.add_dependency "nokogiri", "~> 1.7.1"
|
30
29
|
end
|
data/lib/caller_log.rb
CHANGED
@@ -1,29 +1,51 @@
|
|
1
1
|
require 'caller_log/version'
|
2
2
|
require 'caller_log/log'
|
3
3
|
require 'binding_of_callers'
|
4
|
-
require 'dcr'
|
5
4
|
|
6
5
|
module CallerLog
|
7
6
|
class << self
|
8
7
|
|
9
|
-
def
|
8
|
+
def log *args
|
10
9
|
raise ArgumentError,
|
11
10
|
"wrong number of arguments (given #{args.count}, expected more than 1)" if args.count < 2
|
12
11
|
log_file = args.pop
|
13
|
-
|
12
|
+
objects = Array args
|
14
13
|
|
15
14
|
log = Log.new log_file
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
objects.each do |obj|
|
17
|
+
|
18
|
+
callee = calling obj
|
19
|
+
|
20
|
+
obj.instance_methods(false).each do |method_id|
|
21
|
+
o_method = ref_old method_id
|
22
|
+
obj.send :alias_method, o_method, method_id
|
23
|
+
obj.send :define_method, method_id, &-> *para, &blk {
|
24
|
+
record = OpenStruct.new time: Time.now, callee: "#{callee}##{method_id}", callers: binding.of_callers[1..-1]
|
21
25
|
log.puts record
|
22
|
-
|
23
|
-
|
26
|
+
self.send o_method, *para, &blk
|
27
|
+
}
|
28
|
+
end if obj.is_a? Module
|
29
|
+
|
30
|
+
obj.methods(false).each do |method_id|
|
31
|
+
o_method = obj.method method_id
|
32
|
+
obj.singleton_class.send :define_method, method_id, &-> *para, &blk {
|
33
|
+
record = OpenStruct.new time: Time.now, callee: "#{callee}.#{method_id}", callers: binding.of_callers[1..-1]
|
34
|
+
log.puts record
|
35
|
+
o_method.call *para, &blk
|
36
|
+
}
|
24
37
|
end
|
38
|
+
|
25
39
|
end
|
26
40
|
end
|
41
|
+
|
42
|
+
def calling obj
|
43
|
+
Module === obj ? "#{obj}" : "<#{obj.class}:#{obj.object_id}>"
|
44
|
+
end
|
45
|
+
|
46
|
+
def ref_old method_id
|
47
|
+
"#{method_id}_caller_log"
|
48
|
+
end
|
27
49
|
end
|
28
50
|
|
29
51
|
end
|
data/lib/caller_log/log.rb
CHANGED
@@ -57,14 +57,16 @@ EOHTML
|
|
57
57
|
time = record.time.strftime "%F %T"
|
58
58
|
call = Nokogiri::HTML::DocumentFragment.parse <<-EOHTML
|
59
59
|
<li id='call-#{record.object_id}' class='thread-#{Thread.current.object_id} call'>
|
60
|
-
<span class='time'>#{time}</span><span class='class_and_method'>#{record.
|
60
|
+
<span class='time'>#{time}</span><span class='class_and_method'>#{record.callee}</span>
|
61
61
|
</li>
|
62
62
|
EOHTML
|
63
63
|
base.at_css('.calls') << call
|
64
64
|
end
|
65
65
|
|
66
66
|
def new_stack_fragment record
|
67
|
-
callers = record.callers.
|
67
|
+
callers = record.callers.reject do |c|
|
68
|
+
c.file =~ /caller_log\/lib\/caller_log\.rb/
|
69
|
+
end.map do |c|
|
68
70
|
class_and_method = CGI::escapeHTML "#{c.klass}#{c.call_symbol}#{c.frame_env}"
|
69
71
|
"<p><span class='class_and_method'>#{class_and_method}</span><span class='location'>#{c.file}:#{c.line}</span></p>"
|
70
72
|
end.join
|
@@ -3,18 +3,27 @@
|
|
3
3
|
<head>
|
4
4
|
<meta charset='utf-8'/>
|
5
5
|
<style>
|
6
|
+
html,body {
|
7
|
+
margin: 0;
|
8
|
+
padding: 0;
|
9
|
+
background-color: #E91E63;
|
10
|
+
}
|
6
11
|
ul {
|
7
12
|
padding-left: 0;
|
13
|
+
background-color: white;
|
14
|
+
margin-bottom: 0;
|
8
15
|
}
|
9
16
|
|
10
17
|
li {
|
11
18
|
list-style: none;
|
12
19
|
margin-bottom: .8rem;
|
20
|
+
padding-left: 1rem;
|
13
21
|
}
|
14
22
|
|
15
23
|
ul.threads li {
|
16
24
|
float: left;
|
17
25
|
margin-top: -.5rem;
|
26
|
+
color: white;
|
18
27
|
}
|
19
28
|
|
20
29
|
ul.calls {
|
@@ -23,17 +32,19 @@ ul.calls {
|
|
23
32
|
top: 1rem;
|
24
33
|
bottom: 0;
|
25
34
|
width: 18rem;
|
35
|
+
padding: 1rem 0 1rem 0;
|
26
36
|
overflow: auto;
|
27
37
|
}
|
28
38
|
|
29
39
|
ul.stacks {
|
30
40
|
position: fixed;
|
31
|
-
left:
|
41
|
+
left: 18rem;
|
32
42
|
top: 1rem;
|
33
43
|
bottom: 0;
|
34
44
|
margin-top: 2rem;
|
45
|
+
padding: 1rem 0 1rem 0;
|
35
46
|
overflow: auto;
|
36
|
-
width: calc(100% -
|
47
|
+
width: calc(100% - 18rem);
|
37
48
|
}
|
38
49
|
|
39
50
|
p {
|
@@ -61,6 +72,10 @@ ul.stacks li {
|
|
61
72
|
ul.stacks li.show {
|
62
73
|
display: block;
|
63
74
|
}
|
75
|
+
|
76
|
+
.highlight {
|
77
|
+
color: #03A9F4;
|
78
|
+
}
|
64
79
|
</style>
|
65
80
|
</head>
|
66
81
|
<body>
|
@@ -96,12 +111,19 @@ ul.stacks li.show {
|
|
96
111
|
document.querySelector('.' + call_li.id).classList.add('show');
|
97
112
|
}
|
98
113
|
|
114
|
+
function highlight(call_li){
|
115
|
+
var curr_highlight = document.querySelector('.highlight');
|
116
|
+
curr_highlight && curr_highlight.classList.remove('highlight');
|
117
|
+
call_li.classList.add('highlight');
|
118
|
+
return true;
|
119
|
+
}
|
120
|
+
|
99
121
|
var body = document.getElementsByTagName('body')[0];
|
100
122
|
|
101
123
|
body.addEventListener('click', function(e){
|
102
124
|
var target = e.target;
|
103
125
|
target.type == 'checkbox' && target.checked && show_call(target.value) || hide_call(target.value);
|
104
|
-
e.target.parentElement.classList.contains('call') && toggle_stack(e.target.parentElement);
|
126
|
+
e.target.parentElement.classList.contains('call') && highlight(e.target.parentElement) && toggle_stack(e.target.parentElement);
|
105
127
|
}, false);
|
106
128
|
|
107
129
|
})();
|
data/lib/caller_log/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caller_log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ken
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: dcr
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: binding_of_callers
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
120
|
version: '0'
|
135
121
|
requirements: []
|
136
122
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.
|
123
|
+
rubygems_version: 2.5.2
|
138
124
|
signing_key:
|
139
125
|
specification_version: 4
|
140
126
|
summary: Log every call to a object
|