autolog 0.1.2 → 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.
- data/README.md +29 -29
- data/lib/autolog.rb +10 -4
- data/lib/autolog/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -3,30 +3,15 @@ Autolog
|
|
3
3
|
|
4
4
|
Automatically log tracing events in Ruby more easily.
|
5
5
|
|
6
|
-
To trace Ruby, you can just define `set_trace_func
|
7
|
-
|
8
|
-
set_trace_func proc { |event, file, line, id, binding, classname|
|
9
|
-
printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
|
10
|
-
}
|
11
|
-
t = Test.new
|
12
|
-
t.test
|
13
|
-
|
14
|
-
line prog.rb:11 false
|
15
|
-
c-call prog.rb:11 new Class
|
16
|
-
c-call prog.rb:11 initialize Object
|
17
|
-
c-return prog.rb:11 initialize Object
|
18
|
-
c-return prog.rb:11 new Class
|
19
|
-
line prog.rb:12 false
|
20
|
-
call prog.rb:2 test Test
|
21
|
-
line prog.rb:3 test Test
|
22
|
-
line prog.rb:4 test Test
|
23
|
-
return prog.rb:4 test Test
|
24
|
-
|
25
|
-
But, why not use fewer keystrokes to output debug information? And what about just logging certain sets of events? How about:
|
6
|
+
To trace Ruby, you can just define `set_trace_func`. But, why not use fewer keystrokes to output debug information? And what about just logging certain sets of events? How about:
|
26
7
|
|
27
|
-
|
8
|
+
autolog
|
9
|
+
|
10
|
+
### See also
|
28
11
|
|
29
|
-
|
12
|
+
* [set_trace_func][set_trace_func]
|
13
|
+
* [Tracer][tracer] (part of Ruby stdlib)
|
14
|
+
* [Tracepoint][tracepoint]
|
30
15
|
|
31
16
|
### Installation
|
32
17
|
|
@@ -86,36 +71,50 @@ Or call it on Autolog if that is easier:
|
|
86
71
|
|
87
72
|
### Blocks
|
88
73
|
|
74
|
+
Blocks are nice, because they do an `ensure` to make sure that `autolog :off` happens.
|
75
|
+
|
76
|
+
For example, this will still stop tracing in the end of the block:
|
77
|
+
|
89
78
|
autolog do
|
90
|
-
|
91
|
-
puts "this is something 2"
|
79
|
+
raise Exception.new
|
92
80
|
end
|
93
81
|
|
94
|
-
|
82
|
+
But, this won't:
|
83
|
+
|
84
|
+
autolog
|
85
|
+
raise Exception.new
|
86
|
+
autolog :off
|
87
|
+
|
88
|
+
Although this would:
|
89
|
+
|
90
|
+
begin
|
91
|
+
autolog
|
92
|
+
raise Exception.new
|
93
|
+
ensure
|
94
|
+
autolog :off
|
95
|
+
end
|
96
|
+
|
97
|
+
More examples:
|
95
98
|
|
96
99
|
autolog :methods do
|
97
100
|
# ...
|
98
101
|
end
|
99
102
|
|
100
|
-
or
|
101
103
|
|
102
104
|
autolog :lines do
|
103
105
|
# ...
|
104
106
|
end
|
105
107
|
|
106
|
-
or
|
107
108
|
|
108
109
|
autolog :events, :line, :c_call do
|
109
110
|
# ...
|
110
111
|
end
|
111
112
|
|
112
|
-
or
|
113
113
|
|
114
114
|
Autolog.methods do
|
115
115
|
# ...
|
116
116
|
end
|
117
117
|
|
118
|
-
or
|
119
118
|
|
120
119
|
Autolog.events :line, :c_call do
|
121
120
|
# ...
|
@@ -159,5 +158,6 @@ Copyright (c) 2012 Gary S. Weaver, released under the [MIT license][lic].
|
|
159
158
|
[fork]: https://help.github.com/articles/fork-a-repo
|
160
159
|
[pull]: https://help.github.com/articles/using-pull-requests
|
161
160
|
[tracer]: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/tracer/rdoc/index.html
|
161
|
+
[tracepoint]: https://github.com/rubyworks/tracepoint
|
162
162
|
[set_trace_func]: http://apidock.com/ruby/Kernel/set_trace_func
|
163
163
|
[lic]: http://github.com/garysweaver/autolog/blob/master/LICENSE
|
data/lib/autolog.rb
CHANGED
@@ -5,6 +5,7 @@ module Autolog
|
|
5
5
|
class << self
|
6
6
|
# called procedure instead of proc because set_trace_func proc was calling the proc attribute. Fun!
|
7
7
|
attr_accessor :procedure
|
8
|
+
attr_accessor :flush
|
8
9
|
|
9
10
|
# log all specified events
|
10
11
|
def events(*args)
|
@@ -23,8 +24,11 @@ module Autolog
|
|
23
24
|
end
|
24
25
|
|
25
26
|
if block_given?
|
26
|
-
|
27
|
-
|
27
|
+
begin
|
28
|
+
yield
|
29
|
+
ensure
|
30
|
+
off
|
31
|
+
end
|
28
32
|
end
|
29
33
|
end
|
30
34
|
alias_method :event, :events
|
@@ -147,8 +151,10 @@ end
|
|
147
151
|
Autolog.procedure = lambda {|event, file, line, id, binding, classname| begin; puts "#{event} #{file}.#{line} #{binding} #{classname} #{id}"; rescue SystemExit, Interrupt; raise; rescue Exception; end}
|
148
152
|
|
149
153
|
class Object
|
150
|
-
# make autolog a method
|
151
|
-
|
154
|
+
# make autolog a method on every object except main (?)
|
155
|
+
class << self
|
156
|
+
extend Autolog::Methods
|
157
|
+
end
|
152
158
|
end
|
153
159
|
|
154
160
|
# make autolog a method in main
|
data/lib/autolog/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autolog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-19 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Automatically log events like executed lines, methods, class and module
|
15
15
|
definitions, C-language routines, and/or raises in Ruby.
|