Skip to content
Browse files

release 0.2.0 - better logging output (use inspect when appropriate),…

… better parsing when there is inline rdoc; update micronaut
  • Loading branch information...
1 parent 8196370 commit 7ac1d3c7aaaa9c68a1335592ac1ed92738f1b1ec @rsanheim rsanheim committed Dec 9, 2008
Showing with 86 additions and 52 deletions.
  1. +2 −0 CHANGELOG
  2. +5 −4 Manifest
  3. +14 −6 examples.rb
  4. +5 −1 examples/example_helper.rb
  5. +30 −14 examples/log_example.rb
  6. +1 −2 lib/log_buddy/mixin.rb
  7. +25 −16 lib/log_buddy/utils.rb
  8. +2 −2 lib/log_buddy/version.rb
  9. +2 −2 log_buddy.gemspec
  10. +0 −5 spec/mixin_spec.rb
View
2 CHANGELOG
@@ -1,3 +1,5 @@
+v0.2.0 Better log output of objects based on their type, very similiar to Logger/irb behavior; update to micronaut 0.1.0
+
v0.1.5 Clean up specs and remove noise from spec run
v0.1.4 Micronauts Unite! Test Suite now runs via Micronaut - http://github.com/spicycode/micronaut/
View
9 Manifest
@@ -1,8 +1,4 @@
CHANGELOG
-LICENSE
-Manifest
-README.rdoc
-Rakefile
examples/example_helper.rb
examples/log_buddy_example.rb
examples/log_buddy_init_example.rb
@@ -13,3 +9,8 @@ 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
View
20 examples.rb
@@ -15,9 +15,17 @@ def self.module_method
end
-d "hi" # logs "hi" (regular old logging)
-d { a } # logs "a = 'foo'"
-d { @a } # logs "@a = 'my var'"
-d { @@bar } # logs "@@bar = 'class var!'"
-d { bark } # logs "bark = woof!"
-d { Foo::module_method } # logs Foo::module_method = 'hi!!'
+# LogBuddy calls and their output:
+
+d "hi" # hi
+d { a } # a = "foo"
+d { @a } # @a = "my var"
+d { @@bar } # @@bar = "class var!"
+d { bark } # bark = "woof!"
+d { Foo::module_method } # Foo::module_method = "hi!!"
+
+hsh = {:foo => "bar", "key" => "value"}
+array = [1,2,3,4,"5"]
+
+d { hsh }
+d { array }
View
6 examples/example_helper.rb
@@ -1,6 +1,6 @@
require 'logger'
require 'rubygems'
-gem 'spicycode-micronaut', "= 0.0.4"
+gem 'spicycode-micronaut', "~> 0.1.0"
gem 'mocha'
require "mocha"
require 'micronaut'
@@ -13,4 +13,8 @@ def silence_warnings
$VERBOSE = old_verbose
end
+Micronaut.configure do |config|
+ config.mock_with :mocha
+end
+
Micronaut::Runner.autorun
View
44 examples/log_example.rb
@@ -45,14 +45,14 @@ def self.raise_runtime_error
d {'hi man'}
end
- it "should log a plain arg" do
- LogBuddy.expects(:debug).with('hey yo')
+ it "should log a plain method call as is, nothing fancy" do
+ LogBuddy.expects(:debug).with("hey yo")
d 'hey yo'
end
- it "logs both if given an arg and a block" do
- LogBuddy.expects(:debug).with('hi mom')
- LogBuddy.expects(:debug).with(%[foo = 'foo'\n])
+ it "logs both argument and resulting value if using block from" do
+ LogBuddy.expects(:debug).with("hi mom")
+ LogBuddy.expects(:debug).with(%[foo = "foo"\n])
foo = "foo"
d("hi mom") { foo }
end
@@ -62,42 +62,42 @@ def self.raise_runtime_error
end
it "should output only local vars in the block" do
- LogBuddy.expects(:debug).with(%[a = 'foo'\n])
+ LogBuddy.expects(:debug).with(%[a = "foo"\n])
b = "bad"
a = "foo"
d { a }
end
it "should output instance vars" do
- LogBuddy.expects(:debug).with(%[@a = 'foo'\n])
+ LogBuddy.expects(:debug).with(%[@a = "foo"\n])
@a = "foo"
d { @a }
end
it "should output constants" do
FOO_CONST = "yo!"
- LogBuddy.expects(:debug).with(%[FOO_CONST = 'yo!'\n])
+ LogBuddy.expects(:debug).with(%[FOO_CONST = "yo!"\n])
d { FOO_CONST }
end
it "should output class vars" do
- LogBuddy.expects(:debug).with(%[@@class_var = 'hi'\n])
+ LogBuddy.expects(:debug).with(%[@@class_var = "hi"\n])
@@class_var = "hi"
d { @@class_var }
end
it "should output method calls" do
- LogBuddy.expects(:debug).with(%[SomeModule.say_something("dude!!!!") = 'hello dude!!!!'\n])
+ LogBuddy.expects(:debug).with(%[SomeModule.say_something("dude!!!!") = "hello dude!!!!"\n])
d { SomeModule.say_something("dude!!!!") }
end
it "should output multiple things with each having their own log calls" do
local1 = '1'
local2 = '2'
@ivar1 = '1'
- LogBuddy.expects(:debug).with(%[local1 = '1'\n])
- LogBuddy.expects(:debug).with(%[local2 = '2'\n])
- LogBuddy.expects(:debug).with(%[@ivar1 = '1'\n])
+ LogBuddy.expects(:debug).with(%[local1 = "1"\n])
+ LogBuddy.expects(:debug).with(%[local2 = "2"\n])
+ LogBuddy.expects(:debug).with(%[@ivar1 = "1"\n])
d { local1; local2; @ivar1 }
end
@@ -106,6 +106,22 @@ def self.raise_runtime_error
d { SomeModule.raise_runtime_error }
end
+ it "logs things okay with inline rdoc" do
+ LogBuddy.stubs(:debug)
+ hsh = {:foo=>"bar", "key"=>"value"}
+ d { hsh } # hsh = {:foo=>"bar", "key"=>"value"}
+ end
+
+ it "logs inspected version of hashes and arrays" do
+ hsh = { :peanut_butter => "jelly", "awesome_numbers" => [3,7,22]}
+ different_hash_output_orders = [
+ %[hsh = {"awesome_numbers"=>[3, 7, 22], :peanut_butter=>"jelly"}\n],
+ %[hsh = {:peanut_butter=>"jelly", "awesome_numbers"=>[3, 7, 22]}\n]
+ ]
+ LogBuddy.logger.expects(:debug).with(any_of(*different_hash_output_orders))
+ d { hsh }
+ end
+
end
describe "obj_to_string" do
@@ -140,7 +156,7 @@ def inspect
before { Logger.any_instance.stubs(:debug) }
it "logs to stdout as well as the default logger" do
LogBuddy.init :log_to_stdout => true
- LogBuddy.expects(:stdout_puts).with(%["foo" = 'foo'\n])
+ LogBuddy.expects(:stdout_puts).with(%["foo" = "foo"\n])
d { "foo" }
end
View
3 lib/log_buddy/mixin.rb
@@ -17,8 +17,7 @@ def d(msg = nil, &blk)
logged_line = LogBuddy.read_line(caller[0])
arguments = LogBuddy.parse_args(logged_line)
arguments.each do |arg|
- result = eval(arg, blk.binding)
- LogBuddy.debug(%[#{arg} = '#{result}'\n])
+ LogBuddy.arg_and_blk_debug(arg, blk)
end
rescue RuntimeError => e
LogBuddy.debug "LogBuddy caught an exception: #{e.message}"
View
41 lib/log_buddy/utils.rb
@@ -1,31 +1,26 @@
module LogBuddy
module Utils
- def obj_to_string(obj)
- case obj
- when ::String
- obj
- when ::Exception
- "#{ obj.message } (#{ obj.class })\n" <<
- (obj.backtrace || []).join("\n")
- else
- obj.inspect
- end
- end
-
- def debug(str)
+ def debug(obj)
+ str = obj_to_string(obj)
stdout_puts(str) if log_to_stdout?
logger.debug(str)
end
+
+ def arg_and_blk_debug(arg, blk)
+ result = eval(arg, blk.binding)
+ result_str = obj_to_string(result, :quote_strings => true)
+ LogBuddy.debug(%[#{arg} = #{result_str}\n])
+ end
def stdout_puts(str)
puts str
end
-
+
# Returns array of arguments in the block
- # You must ues the brace form (ie d { "hi" }) and not do...end
+ # You must use the brace form (ie d { "hi" }) and not do...end
def parse_args(logged_line)
- block_contents = logged_line[/\{(.*)\}/, 1]
+ block_contents = logged_line[/\{(.*?)\}/, 1]
args = block_contents.split(";").map {|arg| arg.strip }
end
@@ -37,5 +32,19 @@ def read_line(frame)
lines[line_number - 1]
end
+
+ def obj_to_string(obj, options = {})
+ quote_strings = options.delete(:quote_strings)
+ case obj
+ when ::String
+ quote_strings ? %["#{obj}"] : obj
+ when ::Exception
+ "#{ obj.message } (#{ obj.class })\n" <<
+ (obj.backtrace || []).join("\n")
+ else
+ obj.inspect
+ end
+ end
+
end
end
View
4 lib/log_buddy/version.rb
@@ -1,8 +1,8 @@
module LogBuddy
module VERSION #:nodoc:
MAJOR = 0
- MINOR = 1
- TINY = 5
+ MINOR = 2
+ TINY = 0
STRING = [MAJOR, MINOR, TINY].join('.')
end
View
4 log_buddy.gemspec
@@ -2,11 +2,11 @@
Gem::Specification.new do |s|
s.name = %q{log_buddy}
- s.version = "0.1.5"
+ s.version = "0.2.0"
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Rob Sanheim - Relevance"]
- s.date = %q{2008-12-05}
+ s.date = %q{2008-12-09}
s.description = %q{Log statements along with their name easily. Mixin a logger everywhere when you need it.}
s.email = %q{opensource@thinkrelevance.com}
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "lib/log_buddy/mixin.rb", "lib/log_buddy/utils.rb", "lib/log_buddy/version.rb", "lib/log_buddy.rb", "log_buddy.gemspec"]
View
5 spec/mixin_spec.rb
@@ -1,5 +0,0 @@
-require File.expand_path(File.join(File.dirname(__FILE__), *%w[helper]))
-
-describe LogBuddy::Mixin do
-
-end

0 comments on commit 7ac1d3c

Please sign in to comment.
Something went wrong with that request. Please try again.