log_buddy 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.0.2
2
+ * rdocs
3
+ * support for multiple statements in one "d" call separated by semicolons
4
+
1
5
  === 0.0.1 / 2008-03/28
2
6
 
3
7
  * Initial commit to github
data/Manifest.txt CHANGED
@@ -1,7 +1,6 @@
1
1
  History.txt
2
2
  Manifest.txt
3
3
  README.rdoc
4
- README.txt
5
4
  Rakefile
6
5
  bin/log_buddy
7
6
  examples.rb
data/README.rdoc CHANGED
@@ -1,45 +1,49 @@
1
1
  = LogBuddy
2
-
3
- * Log bugs/issues/suggestions here: http://opensource.thinkrelevance.com/wiki/log_buddy
4
- * Source: http://github.com/relevance/log_buddy/tree/master
5
- * git clone git://github.com/relevance/log_buddy.git
6
- * rdocs:
7
-
2
+
8
3
  == DESCRIPTION:
9
4
 
10
5
  log_buddy is your friendly little log buddy at your side, helping you dev, debug, and test.
11
6
 
12
7
  == SYNOPSIS:
13
8
 
14
- Call LogBuddy.init to use log_buddy. It will add two methods to object instance and class level: "d" and "logger".
9
+ Call LogBuddy.init to use log_buddy. It will add two methods to object instance and class level: "d" and "logger". You can
10
+ use your own logger with Logbuddy by passing it into init's options hash:
11
+
12
+ LogBuddy.init :default_logger => Logger.new('my_log.log')
13
+
14
+ Now you have your logger available from any object, at the instance level and class level:
15
15
 
16
- * The "logger" method is just a typical logger - it will use the Rails logger if its available.
17
- * The "d" method is a special helper that will output the code in the block and its result - note that you *must* use the bracket block form - do...end is not supported.
16
+ obj = Object.new
17
+ obj.logger.debug("hi")
18
+ class MyClass; end
19
+ MyClass.logger.info("heya")
18
20
 
19
- == EXAMPLES:
21
+ You also have a method called "d" (for "debug") on any object, which is used for quick debugging and logging of things while you are developing.
22
+ Its especially useful while using autotest. When you call the "d" method with an inline block, it will log the name of the things
23
+ in the block and the result. Examples:
20
24
 
21
- * see also examples.rb...
25
+ a = "foo"
26
+ @a = "my var"
27
+ @@bar = "class var!"
28
+ def bark
29
+ "woof!"
30
+ end
22
31
 
23
- a = "foo"
24
- @a = "my var"
25
- @@bar = "class var!"
26
- def bark
27
- "woof!"
28
- end
32
+ d { a } # logs "a = 'foo'"
33
+ d { @a } # logs "@a = 'my var'"
34
+ d { @@bar } # logs "@@bar = 'class var!'"
35
+ d { bark } # logs "bark = woof!"
29
36
 
30
- d { a } # logs "a = 'foo'"
31
- d { @a } # logs "@a = 'my var'"
32
- d { @@bar } # logs "@@bar = 'class var!'"
33
- d { bark } # logs "bark = woof!"
34
37
 
38
+ See examples.rb for live examples you can run.
35
39
 
36
40
  == REQUIREMENTS:
37
41
 
38
42
  * Ruby 1.8.6 or JRuby (tested with 1.1RC3)
43
+ * untested on Ruby < 1.8.6, but probably works
39
44
 
40
45
  == ISSUES
41
46
 
42
- * Be careful you don't depend on methods that log_buddy adds to Object in production!
43
47
  * This is meant for non-production use while developing and testing --> it does stuff that is slow and you probably don't want happening in your production environment.
44
48
  * Don't even try using this in irb.
45
49
 
@@ -47,6 +51,13 @@ d { bark } # logs "bark = woof!"
47
51
 
48
52
  * sudo gem log_buddy
49
53
 
54
+ == URLS
55
+
56
+ * Log bugs, issues, and suggestions on Trac: http://opensource.thinkrelevance.com/wiki/log_buddy
57
+ * View Source: http://github.com/relevance/log_buddy/tree/master
58
+ * Git clone Source: git://github.com/relevance/log_buddy.git
59
+ * RDocs: http://thinkrelevance.rubyforge.org/log_buddy/
60
+
50
61
  == LICENSE:
51
62
 
52
63
  (The MIT License)
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'hoe'
3
3
  require './lib/log_buddy.rb'
4
4
 
5
- Hoe.new('log_buddy', LogBuddy::VERSION) do |p|
5
+ hoe = Hoe.new('log_buddy', LogBuddy::VERSION) do |p|
6
6
  p.rubyforge_name = 'thinkrelevance'
7
7
  p.author = 'Rob Sanheim - Relevance'
8
8
  p.email = 'opensource@thinkrelevance.com'
@@ -10,4 +10,24 @@ Hoe.new('log_buddy', LogBuddy::VERSION) do |p|
10
10
  p.description = p.paragraphs_of('README.rdoc', 2..5).join("\n\n")
11
11
  p.url = p.paragraphs_of('README.rdoc', 0).first.split(/\n/)[1..-1]
12
12
  p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
13
+ p.rdoc_pattern = /^(lib|bin|ext)|txt|rdoc$/
14
+ end
15
+
16
+ # Override RDoc to use allison template, and also use our .rdoc README as the main page instead of the default README.txt
17
+ Rake::RDocTask.new(:docs) do |rd|
18
+ gem "allison"
19
+ gem "markaby"
20
+ rd.main = "README.rdoc"
21
+ # rd.options << '-d' if RUBY_PLATFORM !~ /win32/ and `which dot` =~ /\/dot/ and not ENV['NODOT']
22
+ rd.rdoc_dir = 'doc'
23
+ files = hoe.spec.files.grep(hoe.rdoc_pattern)
24
+ files -= ['Manifest.txt']
25
+ rd.rdoc_files.push(*files)
26
+
27
+ title = "#{hoe.name}-#{hoe.version} Documentation"
28
+ title = "#{hoe.rubyforge_name}'s " + title if hoe.rubyforge_name != hoe.name
29
+ rdoc_template = `allison --path`.strip << ".rb"
30
+ rd.template = rdoc_template
31
+ rd.options << "-t #{title}"
32
+ rd.options << '--line-numbers' << '--inline-source'
13
33
  end
data/lib/log_buddy.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  =begin rdoc
2
- LogBuddy is a developer tool for easy logging while testing, debugging, and inspecting.
2
+ LogBuddy is a developer tool for easy logging while testing, debugging, and inspecting.
3
3
 
4
4
  Log shortcut method to give you easy, concise output of variables with their names and values.
5
5
 
@@ -16,13 +16,15 @@ Examples:
16
16
 
17
17
  =end
18
18
  class LogBuddy
19
- VERSION = '0.0.1'
19
+ VERSION = '0.0.2'
20
20
 
21
+ # Use LogBuddy!
21
22
  def self.init(options = {})
22
23
  @logger = options[:default_logger]
23
24
  mixin_to_object
24
25
  end
25
26
 
27
+ # Add the LogBuddy::Mixin to Object instance and class level.
26
28
  def self.mixin_to_object
27
29
  Object.class_eval {
28
30
  include LogBuddy::Mixin
@@ -30,11 +32,44 @@ class LogBuddy
30
32
  }
31
33
  end
32
34
 
35
+ # The main Mixin that gets added on the #init call
36
+ module Mixin
37
+ # This is where the magic happens. This method can take a plain old string, and it will log
38
+ # it like any call to Logger#debug. To get the name of the thing you are logging and its value,
39
+ # use the block form:
40
+ # d { @a }
41
+ #
42
+ # Seperate with semicolons for multiple things - pretty much any valid ruby will work.
43
+ # d { @@foo; MY_CONST }
44
+ # d { @person; @@place; object.method() }
45
+ #
46
+ def d(msg = nil, &blk)
47
+ LogBuddy.debug(msg) if msg
48
+ return unless block_given?
49
+ logged_line = LogBuddy.read_line(caller[0])
50
+ arguments = LogBuddy.parse_args(logged_line)
51
+ arguments.each do |arg|
52
+ result = eval(arg, blk.binding)
53
+ LogBuddy.debug(%[#{arg} = '#{result}'\n])
54
+ end
55
+ end
56
+
57
+ # Add a default logger to everything, everywhere.
58
+ def logger
59
+ LogBuddy.default_logger
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ # Default logger LogBuddy will use
33
66
  def self.default_logger
34
67
  return @logger if @logger
35
68
  @logger = init_default_logger
36
69
  end
37
70
 
71
+ # Attempt to establish a default logger - first try RAILS_DEFAULT_LOGGER,
72
+ # then fallback to default.
38
73
  def self.init_default_logger
39
74
  if Object.const_defined?("RAILS_DEFAULT_LOGGER")
40
75
  @logger = Object.const_get("RAILS_DEFAULT_LOGGER")
@@ -43,15 +78,20 @@ class LogBuddy
43
78
  @logger = Logger.new(STDOUT)
44
79
  end
45
80
  end
46
-
81
+
82
+ # Just debug it
47
83
  def self.debug(str)
48
84
  default_logger.debug(str)
49
85
  end
50
86
 
87
+ # Returns array of arguments in the block
88
+ # You must ues the brace form (ie d { "hi" }) and not do...end
51
89
  def self.parse_args(logged_line)
52
- block_args = logged_line[/\{(.*)\}/, 1].strip
90
+ block_contents = logged_line[/\{(.*)\}/, 1]
91
+ args = block_contents.split(";").map {|arg| arg.strip }
53
92
  end
54
93
 
94
+ # Return the calling line
55
95
  def self.read_line(frame)
56
96
  file, line_number = frame.split(/:/, 2)
57
97
  line_number = line_number.to_i
@@ -60,19 +100,4 @@ class LogBuddy
60
100
  lines[line_number - 1]
61
101
  end
62
102
 
63
- module Mixin
64
- def d(msg = nil, &blk)
65
- LogBuddy.debug(msg) if msg
66
- return unless block_given?
67
- logged_line = LogBuddy.read_line(caller[0])
68
- arguments = LogBuddy.parse_args(logged_line)
69
- result = eval(arguments, blk.binding)
70
- LogBuddy.debug(%[#{arguments} = '#{result}'\n])
71
- end
72
-
73
- def logger
74
- LogBuddy.default_logger
75
- end
76
- end
77
-
78
103
  end
@@ -93,6 +93,12 @@ describe "LogBuddy" do
93
93
  @a = "foo"
94
94
  d { @a }
95
95
  end
96
+
97
+ it "should output constants" do
98
+ FOO_CONST = "yo!"
99
+ LogBuddy.expects(:debug).with(%[FOO_CONST = 'yo!'\n])
100
+ d { FOO_CONST }
101
+ end
96
102
 
97
103
  it "should output class vars" do
98
104
  LogBuddy.expects(:debug).with(%[@@class_var = 'hi'\n])
@@ -104,5 +110,15 @@ describe "LogBuddy" do
104
110
  LogBuddy.expects(:debug).with(%[SomeModule.say_something("dude!!!!") = 'hello dude!!!!'\n])
105
111
  d { SomeModule.say_something("dude!!!!") }
106
112
  end
113
+
114
+ it "should output multiple things with each having their own log calls" do
115
+ local1 = '1'
116
+ local2 = '2'
117
+ @ivar1 = '1'
118
+ LogBuddy.expects(:debug).with(%[local1 = '1'\n])
119
+ LogBuddy.expects(:debug).with(%[local2 = '2'\n])
120
+ LogBuddy.expects(:debug).with(%[@ivar1 = '1'\n])
121
+ d { local1; local2; @ivar1 }
122
+ end
107
123
  end
108
124
  end
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.0.1
4
+ version: 0.0.2
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-03-28 00:00:00 -04:00
12
+ date: 2008-04-04 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -21,7 +21,7 @@ dependencies:
21
21
  - !ruby/object:Gem::Version
22
22
  version: 1.5.1
23
23
  version:
24
- description: "== DESCRIPTION: log_buddy is your friendly little log buddy at your side, helping you dev, debug, and test. == SYNOPSIS: Call LogBuddy.init to use log_buddy. It will add two methods to object instance and class level: \"d\" and \"logger\"."
24
+ description: "== SYNOPSIS: Call LogBuddy.init to use log_buddy. It will add two methods to object instance and class level: \"d\" and \"logger\". You can use your own logger with Logbuddy by passing it into init's options hash: LogBuddy.init :default_logger => Logger.new('my_log.log') Now you have your logger available from any object, at the instance level and class level: obj = Object.new obj.logger.debug(\"hi\") class MyClass; end MyClass.logger.info(\"heya\") You also have a method called \"d\" (for \"debug\") on any object, which is used for quick debugging and logging of things while you are developing. Its especially useful while using autotest. When you call the \"d\" method with an inline block, it will log the name of the things in the block and the result. Examples:"
25
25
  email: opensource@thinkrelevance.com
26
26
  executables:
27
27
  - log_buddy
@@ -30,12 +30,10 @@ extensions: []
30
30
  extra_rdoc_files:
31
31
  - History.txt
32
32
  - Manifest.txt
33
- - README.txt
34
33
  files:
35
34
  - History.txt
36
35
  - Manifest.txt
37
36
  - README.rdoc
38
- - README.txt
39
37
  - Rakefile
40
38
  - bin/log_buddy
41
39
  - examples.rb
@@ -43,7 +41,7 @@ files:
43
41
  - lib/log_buddy.rb
44
42
  - test/test_log_buddy.rb
45
43
  has_rdoc: true
46
- homepage:
44
+ homepage: " "
47
45
  post_install_message:
48
46
  rdoc_options:
49
47
  - --main
data/README.txt DELETED
@@ -1,73 +0,0 @@
1
- = LogBuddy
2
-
3
- * Log bugs/issues/suggestions here: http://opensource.thinkrelevance.com/wiki/log_buddy
4
- * Source: http://github.com/relevance/log_buddy/tree/master
5
- * git clone git://github.com/relevance/log_buddy.git
6
- * rdocs:
7
-
8
- == DESCRIPTION:
9
-
10
- log_buddy is your friendly little log buddy at your side, helping you dev, debug, and test.
11
-
12
- == SYNOPSIS:
13
-
14
- Call LogBuddy.init to use log_buddy. It will add two methods to object instance and class level: "d" and "logger".
15
-
16
- * The "logger" method is just a typical logger - it will use the Rails logger if its available.
17
- * The "d" method is a special helper that will output the code in the block and its result - note that you *must* use the bracket block form - do...end is not supported.
18
-
19
- == EXAMPLES:
20
-
21
- * see also examples.rb...
22
-
23
- a = "foo"
24
- @a = "my var"
25
- @@bar = "class var!"
26
- def bark
27
- "woof!"
28
- end
29
-
30
- d { a } # logs "a = 'foo'"
31
- d { @a } # logs "@a = 'my var'"
32
- d { @@bar } # logs "@@bar = 'class var!'"
33
- d { bark } # logs "bark = woof!"
34
-
35
-
36
- == REQUIREMENTS:
37
-
38
- * Ruby 1.8.6 or JRuby (tested with 1.1RC3)
39
-
40
- == ISSUES
41
-
42
- * Be careful you don't depend on methods that log_buddy adds to Object in production!
43
- * This is meant for non-production use while developing and testing --> it does stuff that is slow and you probably don't want happening in your production environment.
44
- * Don't even try using this in irb.
45
-
46
- == INSTALL:
47
-
48
- * sudo gem log_buddy
49
-
50
- == LICENSE:
51
-
52
- (The MIT License)
53
-
54
- Copyright (c) 2008 Relevance, Inc. - http://thinkrelevance.com
55
-
56
- Permission is hereby granted, free of charge, to any person obtaining
57
- a copy of this software and associated documentation files (the
58
- 'Software'), to deal in the Software without restriction, including
59
- without limitation the rights to use, copy, modify, merge, publish,
60
- distribute, sublicense, and/or sell copies of the Software, and to
61
- permit persons to whom the Software is furnished to do so, subject to
62
- the following conditions:
63
-
64
- The above copyright notice and this permission notice shall be
65
- included in all copies or substantial portions of the Software.
66
-
67
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
68
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
69
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
70
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
71
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
72
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
73
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.