log_buddy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +10 -0
- data/README.rdoc +73 -0
- data/README.txt +73 -0
- data/Rakefile +13 -0
- data/bin/log_buddy +0 -0
- data/examples.rb +22 -0
- data/init.rb +1 -0
- data/lib/log_buddy.rb +78 -0
- data/test/test_log_buddy.rb +108 -0
- metadata +73 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,73 @@
|
|
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.
|
data/README.txt
ADDED
@@ -0,0 +1,73 @@
|
|
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.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hoe'
|
3
|
+
require './lib/log_buddy.rb'
|
4
|
+
|
5
|
+
Hoe.new('log_buddy', LogBuddy::VERSION) do |p|
|
6
|
+
p.rubyforge_name = 'thinkrelevance'
|
7
|
+
p.author = 'Rob Sanheim - Relevance'
|
8
|
+
p.email = 'opensource@thinkrelevance.com'
|
9
|
+
p.summary = 'Log Buddy is your little development buddy.'
|
10
|
+
p.description = p.paragraphs_of('README.rdoc', 2..5).join("\n\n")
|
11
|
+
p.url = p.paragraphs_of('README.rdoc', 0).first.split(/\n/)[1..-1]
|
12
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
13
|
+
end
|
data/bin/log_buddy
ADDED
File without changes
|
data/examples.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'lib/log_buddy'
|
2
|
+
LogBuddy.init
|
3
|
+
|
4
|
+
a = "foo"
|
5
|
+
@a = "my var"
|
6
|
+
@@bar = "class var!"
|
7
|
+
def bark
|
8
|
+
"woof!"
|
9
|
+
end
|
10
|
+
|
11
|
+
module Foo;
|
12
|
+
def self.module_method
|
13
|
+
"hi!!"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
d { a } # logs "a = 'foo'"
|
19
|
+
d { @a } # logs "@a = 'my var'"
|
20
|
+
d { @@bar } # logs "@@bar = 'class var!'"
|
21
|
+
d { bark } # logs "bark = woof!"
|
22
|
+
d { Foo::module_method } # logs Foo::module_method = 'hi!!'
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'log_buddy'
|
data/lib/log_buddy.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
LogBuddy is a developer tool for easy logging while testing, debugging, and inspecting.
|
3
|
+
|
4
|
+
Log shortcut method to give you easy, concise output of variables with their names and values.
|
5
|
+
|
6
|
+
Examples:
|
7
|
+
a = "foo"
|
8
|
+
@a = "my var"
|
9
|
+
def bark
|
10
|
+
"woof!"
|
11
|
+
end
|
12
|
+
|
13
|
+
d { a } # logs "a = 'foo'"
|
14
|
+
d { @a } # logs "@a = 'my var'"
|
15
|
+
d { bark } # logs "bark = woof!"
|
16
|
+
|
17
|
+
=end
|
18
|
+
class LogBuddy
|
19
|
+
VERSION = '0.0.1'
|
20
|
+
|
21
|
+
def self.init(options = {})
|
22
|
+
@logger = options[:default_logger]
|
23
|
+
mixin_to_object
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.mixin_to_object
|
27
|
+
Object.class_eval {
|
28
|
+
include LogBuddy::Mixin
|
29
|
+
extend LogBuddy::Mixin
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.default_logger
|
34
|
+
return @logger if @logger
|
35
|
+
@logger = init_default_logger
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.init_default_logger
|
39
|
+
if Object.const_defined?("RAILS_DEFAULT_LOGGER")
|
40
|
+
@logger = Object.const_get("RAILS_DEFAULT_LOGGER")
|
41
|
+
else
|
42
|
+
require 'logger'
|
43
|
+
@logger = Logger.new(STDOUT)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.debug(str)
|
48
|
+
default_logger.debug(str)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.parse_args(logged_line)
|
52
|
+
block_args = logged_line[/\{(.*)\}/, 1].strip
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.read_line(frame)
|
56
|
+
file, line_number = frame.split(/:/, 2)
|
57
|
+
line_number = line_number.to_i
|
58
|
+
lines = File.readlines(file)
|
59
|
+
|
60
|
+
lines[line_number - 1]
|
61
|
+
end
|
62
|
+
|
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
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require "test/unit"
|
3
|
+
require "test/spec"
|
4
|
+
require "test/spec/should-output"
|
5
|
+
require 'mocha'
|
6
|
+
require 'logger'
|
7
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "log_buddy"))
|
8
|
+
|
9
|
+
module SomeModule
|
10
|
+
def self.say_something(name)
|
11
|
+
"#{message} #{name}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.message
|
15
|
+
"hello"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "LogBuddy" do
|
20
|
+
|
21
|
+
describe "raise no method error if init isn't called" do
|
22
|
+
lambda { Object.new.d }.should.raise NoMethodError
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "object extensions" do
|
26
|
+
it "mixes itself into Object intance and class level by default" do
|
27
|
+
Object.expects(:include).with(LogBuddy::Mixin)
|
28
|
+
Object.expects(:extend).with(LogBuddy::Mixin)
|
29
|
+
LogBuddy.init
|
30
|
+
end
|
31
|
+
|
32
|
+
it "adds logger method to Object instance and class" do
|
33
|
+
LogBuddy.init
|
34
|
+
Object.new.should.respond_to :logger
|
35
|
+
Object.should.respond_to :logger
|
36
|
+
end
|
37
|
+
|
38
|
+
it "uses RAILS_DEFAULT_LOGGER if its defined" do
|
39
|
+
begin
|
40
|
+
Object.const_set "RAILS_DEFAULT_LOGGER", stub_everything
|
41
|
+
LogBuddy.init
|
42
|
+
Object.logger.should == RAILS_DEFAULT_LOGGER
|
43
|
+
ensure
|
44
|
+
Object.send :remove_const, "RAILS_DEFAULT_LOGGER"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "uses a plain STDOUT Ruby logger if there is no RAILS_DEFAULT_LOGGER" do
|
49
|
+
LogBuddy.init
|
50
|
+
Object.logger.should == LogBuddy.default_logger
|
51
|
+
end
|
52
|
+
|
53
|
+
it "can override the default logger" do
|
54
|
+
file_logger = Logger.new "test.log"
|
55
|
+
LogBuddy.init :default_logger => file_logger
|
56
|
+
Object.logger.should == file_logger
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "outputting the code being logged and its result" do
|
61
|
+
before { LogBuddy.init }
|
62
|
+
it "should log to default logger" do
|
63
|
+
LogBuddy.expects(:default_logger).returns(logger = mock)
|
64
|
+
logger.expects(:debug).with(anything)
|
65
|
+
d {'hi'}
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should log a plain arg" do
|
69
|
+
LogBuddy.expects(:debug).with('hi')
|
70
|
+
d 'hi'
|
71
|
+
end
|
72
|
+
|
73
|
+
it "logs both if given an arg and a block" do
|
74
|
+
LogBuddy.expects(:debug).with('hi mom')
|
75
|
+
LogBuddy.expects(:debug).with(%[foo = 'foo'\n])
|
76
|
+
foo = "foo"
|
77
|
+
d("hi mom") { foo }
|
78
|
+
end
|
79
|
+
|
80
|
+
it "does nothing without a block" do
|
81
|
+
should.not.raise { d }
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should output only local vars in the block" do
|
85
|
+
LogBuddy.expects(:debug).with(%[a = 'foo'\n])
|
86
|
+
b = "bad"
|
87
|
+
a = "foo"
|
88
|
+
d { a }
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should output instance vars" do
|
92
|
+
LogBuddy.expects(:debug).with(%[@a = 'foo'\n])
|
93
|
+
@a = "foo"
|
94
|
+
d { @a }
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should output class vars" do
|
98
|
+
LogBuddy.expects(:debug).with(%[@@class_var = 'hi'\n])
|
99
|
+
@@class_var = "hi"
|
100
|
+
d { @@class_var }
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should output method calls" do
|
104
|
+
LogBuddy.expects(:debug).with(%[SomeModule.say_something("dude!!!!") = 'hello dude!!!!'\n])
|
105
|
+
d { SomeModule.say_something("dude!!!!") }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: log_buddy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rob Sanheim - Relevance
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-03-28 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.5.1
|
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\"."
|
25
|
+
email: opensource@thinkrelevance.com
|
26
|
+
executables:
|
27
|
+
- log_buddy
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- History.txt
|
32
|
+
- Manifest.txt
|
33
|
+
- README.txt
|
34
|
+
files:
|
35
|
+
- History.txt
|
36
|
+
- Manifest.txt
|
37
|
+
- README.rdoc
|
38
|
+
- README.txt
|
39
|
+
- Rakefile
|
40
|
+
- bin/log_buddy
|
41
|
+
- examples.rb
|
42
|
+
- init.rb
|
43
|
+
- lib/log_buddy.rb
|
44
|
+
- test/test_log_buddy.rb
|
45
|
+
has_rdoc: true
|
46
|
+
homepage:
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --main
|
50
|
+
- README.txt
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: thinkrelevance
|
68
|
+
rubygems_version: 1.0.1
|
69
|
+
signing_key:
|
70
|
+
specification_version: 2
|
71
|
+
summary: Log Buddy is your little development buddy.
|
72
|
+
test_files:
|
73
|
+
- test/test_log_buddy.rb
|