log_buddy 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +5 -4
- data/README.rdoc +1 -0
- data/Rakefile +2 -2
- data/examples.rb +14 -6
- data/examples/example_helper.rb +5 -1
- data/examples/log_example.rb +58 -14
- data/lib/log_buddy/mixin.rb +1 -2
- data/lib/log_buddy/utils.rb +25 -4
- data/lib/log_buddy/version.rb +2 -2
- data/log_buddy.gemspec +5 -5
- metadata +10 -9
data/CHANGELOG
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
v0.2.0 Better log output of objects based on their type, very similiar to Logger/irb behavior; update to micronaut 0.1.0
|
2
|
+
|
1
3
|
v0.1.5 Clean up specs and remove noise from spec run
|
2
4
|
|
3
5
|
v0.1.4 Micronauts Unite! Test Suite now runs via Micronaut - http://github.com/spicycode/micronaut/
|
data/Manifest
CHANGED
@@ -1,8 +1,4 @@
|
|
1
1
|
CHANGELOG
|
2
|
-
LICENSE
|
3
|
-
Manifest
|
4
|
-
README.rdoc
|
5
|
-
Rakefile
|
6
2
|
examples/example_helper.rb
|
7
3
|
examples/log_buddy_example.rb
|
8
4
|
examples/log_buddy_init_example.rb
|
@@ -13,3 +9,8 @@ lib/log_buddy/mixin.rb
|
|
13
9
|
lib/log_buddy/utils.rb
|
14
10
|
lib/log_buddy/version.rb
|
15
11
|
lib/log_buddy.rb
|
12
|
+
LICENSE
|
13
|
+
log_buddy.gemspec
|
14
|
+
Manifest
|
15
|
+
Rakefile
|
16
|
+
README.rdoc
|
data/README.rdoc
CHANGED
@@ -57,6 +57,7 @@ See examples.rb for live examples you can run.
|
|
57
57
|
* Log bugs, issues, and suggestions at Lighthouse: http://relevance.lighthouseapp.com/projects/19074-log-buddy/overview
|
58
58
|
* View Source: http://github.com/relevance/logbuddy
|
59
59
|
* Git clone Source: git://github.com/relevance/logbuddy.git
|
60
|
+
* Continuous Integration: http://runcoderun.com/relevance/logbuddy
|
60
61
|
* RDocs: http://thinkrelevance.rubyforge.org/log_buddy
|
61
62
|
|
62
63
|
== LICENSE:
|
data/Rakefile
CHANGED
@@ -9,8 +9,8 @@ echoe = Echoe.new('log_buddy', LogBuddy::VERSION::STRING) do |p|
|
|
9
9
|
p.email = 'opensource@thinkrelevance.com'
|
10
10
|
p.summary = 'Log Buddy is your little development buddy.'
|
11
11
|
p.description = 'Log statements along with their name easily. Mixin a logger everywhere when you need it.'
|
12
|
-
p.url = "http://
|
13
|
-
p.rdoc_pattern = /^(lib|bin|ext)|txt|rdoc|CHANGELOG|LICENSE$/
|
12
|
+
p.url = "http://github.com/relevance/logbuddy"
|
13
|
+
p.rdoc_pattern = /^(lib|bin|ext)|txt|rdoc|gemspec|CHANGELOG|LICENSE$/
|
14
14
|
rdoc_template = `allison --path`.strip << ".rb"
|
15
15
|
p.rdoc_template = rdoc_template
|
16
16
|
end
|
data/examples.rb
CHANGED
@@ -15,9 +15,17 @@ module Foo;
|
|
15
15
|
end
|
16
16
|
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
d
|
21
|
-
d {
|
22
|
-
d {
|
23
|
-
d {
|
18
|
+
# LogBuddy calls and their output:
|
19
|
+
|
20
|
+
d "hi" # hi
|
21
|
+
d { a } # a = "foo"
|
22
|
+
d { @a } # @a = "my var"
|
23
|
+
d { @@bar } # @@bar = "class var!"
|
24
|
+
d { bark } # bark = "woof!"
|
25
|
+
d { Foo::module_method } # Foo::module_method = "hi!!"
|
26
|
+
|
27
|
+
hsh = {:foo => "bar", "key" => "value"}
|
28
|
+
array = [1,2,3,4,"5"]
|
29
|
+
|
30
|
+
d { hsh }
|
31
|
+
d { array }
|
data/examples/example_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require 'rubygems'
|
3
|
-
gem 'spicycode-micronaut', "
|
3
|
+
gem 'spicycode-micronaut', "~> 0.1.0"
|
4
4
|
gem 'mocha'
|
5
5
|
require "mocha"
|
6
6
|
require 'micronaut'
|
@@ -13,4 +13,8 @@ ensure
|
|
13
13
|
$VERBOSE = old_verbose
|
14
14
|
end
|
15
15
|
|
16
|
+
Micronaut.configure do |config|
|
17
|
+
config.mock_with :mocha
|
18
|
+
end
|
19
|
+
|
16
20
|
Micronaut::Runner.autorun
|
data/examples/log_example.rb
CHANGED
@@ -45,14 +45,14 @@ describe LogBuddy::Mixin, " behavior" do
|
|
45
45
|
d {'hi man'}
|
46
46
|
end
|
47
47
|
|
48
|
-
it "should log a plain
|
49
|
-
LogBuddy.expects(:debug).with(
|
48
|
+
it "should log a plain method call as is, nothing fancy" do
|
49
|
+
LogBuddy.expects(:debug).with("hey yo")
|
50
50
|
d 'hey yo'
|
51
51
|
end
|
52
52
|
|
53
|
-
it "logs both
|
54
|
-
LogBuddy.expects(:debug).with(
|
55
|
-
LogBuddy.expects(:debug).with(%[foo =
|
53
|
+
it "logs both argument and resulting value if using block from" do
|
54
|
+
LogBuddy.expects(:debug).with("hi mom")
|
55
|
+
LogBuddy.expects(:debug).with(%[foo = "foo"\n])
|
56
56
|
foo = "foo"
|
57
57
|
d("hi mom") { foo }
|
58
58
|
end
|
@@ -62,32 +62,32 @@ describe LogBuddy::Mixin, " behavior" do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should output only local vars in the block" do
|
65
|
-
LogBuddy.expects(:debug).with(%[a =
|
65
|
+
LogBuddy.expects(:debug).with(%[a = "foo"\n])
|
66
66
|
b = "bad"
|
67
67
|
a = "foo"
|
68
68
|
d { a }
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should output instance vars" do
|
72
|
-
LogBuddy.expects(:debug).with(%[@a =
|
72
|
+
LogBuddy.expects(:debug).with(%[@a = "foo"\n])
|
73
73
|
@a = "foo"
|
74
74
|
d { @a }
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should output constants" do
|
78
78
|
FOO_CONST = "yo!"
|
79
|
-
LogBuddy.expects(:debug).with(%[FOO_CONST =
|
79
|
+
LogBuddy.expects(:debug).with(%[FOO_CONST = "yo!"\n])
|
80
80
|
d { FOO_CONST }
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should output class vars" do
|
84
|
-
LogBuddy.expects(:debug).with(%[@@class_var =
|
84
|
+
LogBuddy.expects(:debug).with(%[@@class_var = "hi"\n])
|
85
85
|
@@class_var = "hi"
|
86
86
|
d { @@class_var }
|
87
87
|
end
|
88
88
|
|
89
89
|
it "should output method calls" do
|
90
|
-
LogBuddy.expects(:debug).with(%[SomeModule.say_something("dude!!!!") =
|
90
|
+
LogBuddy.expects(:debug).with(%[SomeModule.say_something("dude!!!!") = "hello dude!!!!"\n])
|
91
91
|
d { SomeModule.say_something("dude!!!!") }
|
92
92
|
end
|
93
93
|
|
@@ -95,9 +95,9 @@ describe LogBuddy::Mixin, " behavior" do
|
|
95
95
|
local1 = '1'
|
96
96
|
local2 = '2'
|
97
97
|
@ivar1 = '1'
|
98
|
-
LogBuddy.expects(:debug).with(%[local1 =
|
99
|
-
LogBuddy.expects(:debug).with(%[local2 =
|
100
|
-
LogBuddy.expects(:debug).with(%[@ivar1 =
|
98
|
+
LogBuddy.expects(:debug).with(%[local1 = "1"\n])
|
99
|
+
LogBuddy.expects(:debug).with(%[local2 = "2"\n])
|
100
|
+
LogBuddy.expects(:debug).with(%[@ivar1 = "1"\n])
|
101
101
|
d { local1; local2; @ivar1 }
|
102
102
|
end
|
103
103
|
|
@@ -106,13 +106,57 @@ describe LogBuddy::Mixin, " behavior" do
|
|
106
106
|
d { SomeModule.raise_runtime_error }
|
107
107
|
end
|
108
108
|
|
109
|
+
it "logs things okay with inline rdoc" do
|
110
|
+
LogBuddy.stubs(:debug)
|
111
|
+
hsh = {:foo=>"bar", "key"=>"value"}
|
112
|
+
d { hsh } # hsh = {:foo=>"bar", "key"=>"value"}
|
113
|
+
end
|
114
|
+
|
115
|
+
it "logs inspected version of hashes and arrays" do
|
116
|
+
hsh = { :peanut_butter => "jelly", "awesome_numbers" => [3,7,22]}
|
117
|
+
different_hash_output_orders = [
|
118
|
+
%[hsh = {"awesome_numbers"=>[3, 7, 22], :peanut_butter=>"jelly"}\n],
|
119
|
+
%[hsh = {:peanut_butter=>"jelly", "awesome_numbers"=>[3, 7, 22]}\n]
|
120
|
+
]
|
121
|
+
LogBuddy.logger.expects(:debug).with(any_of(*different_hash_output_orders))
|
122
|
+
d { hsh }
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "obj_to_string" do
|
128
|
+
include LogBuddy::Utils
|
129
|
+
|
130
|
+
class Foo
|
131
|
+
def inspect
|
132
|
+
"inspeck yo-self"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
it "logs string as-is" do
|
137
|
+
obj_to_string("foo").should == "foo"
|
138
|
+
end
|
139
|
+
|
140
|
+
it "logs exception with exception msg, type, and backtrace" do
|
141
|
+
begin
|
142
|
+
raise "bad mojo"
|
143
|
+
rescue Exception => exception
|
144
|
+
string = obj_to_string(exception)
|
145
|
+
string.should match /^bad mojo (RuntimeError)*/
|
146
|
+
string.should include(__FILE__)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
it "logs all other objects with #inspect" do
|
151
|
+
obj_to_string(Foo.new).should == "inspeck yo-self"
|
152
|
+
end
|
109
153
|
end
|
110
154
|
|
111
155
|
describe "stdout" do
|
112
156
|
before { Logger.any_instance.stubs(:debug) }
|
113
157
|
it "logs to stdout as well as the default logger" do
|
114
158
|
LogBuddy.init :log_to_stdout => true
|
115
|
-
LogBuddy.expects(:stdout_puts).with(%["foo" =
|
159
|
+
LogBuddy.expects(:stdout_puts).with(%["foo" = "foo"\n])
|
116
160
|
d { "foo" }
|
117
161
|
end
|
118
162
|
|
data/lib/log_buddy/mixin.rb
CHANGED
@@ -17,8 +17,7 @@ module LogBuddy
|
|
17
17
|
logged_line = LogBuddy.read_line(caller[0])
|
18
18
|
arguments = LogBuddy.parse_args(logged_line)
|
19
19
|
arguments.each do |arg|
|
20
|
-
|
21
|
-
LogBuddy.debug(%[#{arg} = '#{result}'\n])
|
20
|
+
LogBuddy.arg_and_blk_debug(arg, blk)
|
22
21
|
end
|
23
22
|
rescue RuntimeError => e
|
24
23
|
LogBuddy.debug "LogBuddy caught an exception: #{e.message}"
|
data/lib/log_buddy/utils.rb
CHANGED
@@ -1,19 +1,26 @@
|
|
1
1
|
module LogBuddy
|
2
2
|
module Utils
|
3
3
|
|
4
|
-
def debug(
|
4
|
+
def debug(obj)
|
5
|
+
str = obj_to_string(obj)
|
5
6
|
stdout_puts(str) if log_to_stdout?
|
6
7
|
logger.debug(str)
|
7
8
|
end
|
9
|
+
|
10
|
+
def arg_and_blk_debug(arg, blk)
|
11
|
+
result = eval(arg, blk.binding)
|
12
|
+
result_str = obj_to_string(result, :quote_strings => true)
|
13
|
+
LogBuddy.debug(%[#{arg} = #{result_str}\n])
|
14
|
+
end
|
8
15
|
|
9
16
|
def stdout_puts(str)
|
10
17
|
puts str
|
11
18
|
end
|
12
|
-
|
19
|
+
|
13
20
|
# Returns array of arguments in the block
|
14
|
-
# You must
|
21
|
+
# You must use the brace form (ie d { "hi" }) and not do...end
|
15
22
|
def parse_args(logged_line)
|
16
|
-
block_contents = logged_line[/\{(
|
23
|
+
block_contents = logged_line[/\{(.*?)\}/, 1]
|
17
24
|
args = block_contents.split(";").map {|arg| arg.strip }
|
18
25
|
end
|
19
26
|
|
@@ -25,5 +32,19 @@ module LogBuddy
|
|
25
32
|
|
26
33
|
lines[line_number - 1]
|
27
34
|
end
|
35
|
+
|
36
|
+
def obj_to_string(obj, options = {})
|
37
|
+
quote_strings = options.delete(:quote_strings)
|
38
|
+
case obj
|
39
|
+
when ::String
|
40
|
+
quote_strings ? %["#{obj}"] : obj
|
41
|
+
when ::Exception
|
42
|
+
"#{ obj.message } (#{ obj.class })\n" <<
|
43
|
+
(obj.backtrace || []).join("\n")
|
44
|
+
else
|
45
|
+
obj.inspect
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
28
49
|
end
|
29
50
|
end
|
data/lib/log_buddy/version.rb
CHANGED
data/log_buddy.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{log_buddy}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.2.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Rob Sanheim - Relevance"]
|
9
|
-
s.date = %q{2008-12-
|
9
|
+
s.date = %q{2008-12-09}
|
10
10
|
s.description = %q{Log statements along with their name easily. Mixin a logger everywhere when you need it.}
|
11
11
|
s.email = %q{opensource@thinkrelevance.com}
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG", "
|
13
|
-
s.files = ["CHANGELOG", "
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/log_buddy/mixin.rb", "lib/log_buddy/utils.rb", "lib/log_buddy/version.rb", "lib/log_buddy.rb", "LICENSE", "log_buddy.gemspec", "README.rdoc"]
|
13
|
+
s.files = ["CHANGELOG", "examples/example_helper.rb", "examples/log_buddy_example.rb", "examples/log_buddy_init_example.rb", "examples/log_example.rb", "examples.rb", "init.rb", "lib/log_buddy/mixin.rb", "lib/log_buddy/utils.rb", "lib/log_buddy/version.rb", "lib/log_buddy.rb", "LICENSE", "log_buddy.gemspec", "Manifest", "Rakefile", "README.rdoc"]
|
14
14
|
s.has_rdoc = true
|
15
|
-
s.homepage = %q{http://
|
15
|
+
s.homepage = %q{http://github.com/relevance/logbuddy}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Log_buddy", "--main", "README.rdoc"]
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
s.rubyforge_project = %q{thinkrelevance}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: log_buddy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Sanheim - Relevance
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-12-
|
12
|
+
date: 2008-12-09 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -60,18 +60,15 @@ extensions: []
|
|
60
60
|
|
61
61
|
extra_rdoc_files:
|
62
62
|
- CHANGELOG
|
63
|
-
- LICENSE
|
64
|
-
- README.rdoc
|
65
63
|
- lib/log_buddy/mixin.rb
|
66
64
|
- lib/log_buddy/utils.rb
|
67
65
|
- lib/log_buddy/version.rb
|
68
66
|
- lib/log_buddy.rb
|
69
|
-
files:
|
70
|
-
- CHANGELOG
|
71
67
|
- LICENSE
|
72
|
-
-
|
68
|
+
- log_buddy.gemspec
|
73
69
|
- README.rdoc
|
74
|
-
|
70
|
+
files:
|
71
|
+
- CHANGELOG
|
75
72
|
- examples/example_helper.rb
|
76
73
|
- examples/log_buddy_example.rb
|
77
74
|
- examples/log_buddy_init_example.rb
|
@@ -82,9 +79,13 @@ files:
|
|
82
79
|
- lib/log_buddy/utils.rb
|
83
80
|
- lib/log_buddy/version.rb
|
84
81
|
- lib/log_buddy.rb
|
82
|
+
- LICENSE
|
85
83
|
- log_buddy.gemspec
|
84
|
+
- Manifest
|
85
|
+
- Rakefile
|
86
|
+
- README.rdoc
|
86
87
|
has_rdoc: true
|
87
|
-
homepage: http://
|
88
|
+
homepage: http://github.com/relevance/logbuddy
|
88
89
|
post_install_message:
|
89
90
|
rdoc_options:
|
90
91
|
- --line-numbers
|