debug_log 0.0.3 → 0.1.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/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
+ doc/*
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- debug_log (0.0.3)
4
+ debug_log (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -0,0 +1,30 @@
1
+ = Debug Log
2
+
3
+ This is a simple RubyGem that provides a more convenient and powerful way of doing debug printouts than using
4
+ puts or a logger directly.
5
+
6
+ == Usage
7
+
8
+ Require the gem. If you are using Bundler, add this to your Gemfile:
9
+
10
+ gem 'debug_log', '~> version known to work'
11
+
12
+ Now you can do debug printouts like this:
13
+
14
+ my_list = [:a, :b, :c]
15
+ my_number = 5
16
+ debug.log("at the end of bar", "my_number", "my_list.size")
17
+
18
+ The first argument to the log method is a comment and the following arguments are Ruby expression that will be evaluated. Here is an example of what the output can look like:
19
+
20
+ DebugLog | at the end of bar | my_number="5" (Fixnum), my_list.size="3" (Fixnum) | /Users/peter/tmp/debug-example.rb:7:in `foo'
21
+
22
+ By default the logger will log to stdout, but you can change that through the configuration options:
23
+
24
+ DebugLog.logger = lambda { |message| Rails.logger.info(message) }
25
+ DebugLog.stdout = false # defaults to true
26
+ DebugLog.enabled = false # defaults to true
27
+
28
+ == Credit
29
+
30
+ The approach to patching the binding object was taken from Niclas Nilssons presentation "The Ruby advantage - metaprogramming and DSLs" at Nordic Ruby 2010. Niclas has packaged up his own solution to debug printouts in his {dp gem}[https://github.com/niclasnilsson/dp].
@@ -33,7 +33,7 @@ module DebugLog
33
33
  return unless enabled
34
34
  message = [prefix, comment, expression_string(binding, *expressions), calling_method].join(separator)
35
35
  puts(message) if stdout
36
- logger.info(message) if logger
36
+ logger.call(message) if logger
37
37
  end
38
38
 
39
39
  def self.expression_string(binding, *expressions)
@@ -1,3 +1,3 @@
1
1
  module DebugLog
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -39,9 +39,9 @@ describe DebugLog do
39
39
  invoke_log
40
40
  end
41
41
 
42
- it "invokes info on the logger object if there is one" do
42
+ it "invokes logger object if there is one" do
43
43
  logger = Logger.new($stdout)
44
- DebugLog.logger = logger
44
+ DebugLog.logger = lambda { |message| logger.info(message) }
45
45
 
46
46
  log_expectations
47
47
  DebugLog.expects(:puts).with(@expected_message)
@@ -71,7 +71,7 @@ describe DebugLog do
71
71
  describe "logger" do
72
72
  it "defaults to nil but can be initialized to a logger object" do
73
73
  DebugLog.logger.should be_nil
74
- logger = Logger.new($stdout)
74
+ logger = lambda { |message| puts message }
75
75
  DebugLog.logger = logger
76
76
  DebugLog.logger.should == logger
77
77
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 3
9
- version: 0.0.3
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Peter Marklund
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-01 00:00:00 +01:00
17
+ date: 2010-11-05 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -60,6 +60,7 @@ files:
60
60
  - .gitignore
61
61
  - Gemfile
62
62
  - Gemfile.lock
63
+ - README.rdoc
63
64
  - Rakefile
64
65
  - debug_log.gemspec
65
66
  - lib/debug_log.rb
@@ -81,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
82
  requirements:
82
83
  - - ">="
83
84
  - !ruby/object:Gem::Version
84
- hash: -634113617
85
+ hash: -720494829
85
86
  segments:
86
87
  - 0
87
88
  version: "0"
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  requirements:
91
92
  - - ">="
92
93
  - !ruby/object:Gem::Version
93
- hash: -634113617
94
+ hash: -720494829
94
95
  segments:
95
96
  - 0
96
97
  version: "0"