loggable 0.1.0 → 0.2.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/README.rdoc +81 -0
- data/Rakefile +18 -24
- data/lib/loggable.rb +13 -2
- data/lib/loggable/log_methods.rb +1 -1
- data/lib/loggable/version.rb +7 -5
- data/test/examples/log_methods_test.rb +20 -0
- data/test/test_helper.rb +1 -4
- metadata +10 -12
- data/HISTORY +0 -10
- data/LICENSE +0 -20
- data/README +0 -57
data/README.rdoc
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
= Loggable
|
2
|
+
|
3
|
+
Loggable is a gem that's designed to add a logging interface to classes that don't
|
4
|
+
automatically support it.
|
5
|
+
|
6
|
+
== Installation
|
7
|
+
|
8
|
+
Stable:
|
9
|
+
|
10
|
+
sudo gem install loggable
|
11
|
+
|
12
|
+
Bleeding Edge (hardly):
|
13
|
+
|
14
|
+
sudo gem install vigetlabs-loggable --source=http://gems.github.com
|
15
|
+
|
16
|
+
== Usage
|
17
|
+
|
18
|
+
Using the Gem is easy, just assign a new logger to your class:
|
19
|
+
|
20
|
+
require 'rubygems'
|
21
|
+
require 'logger'
|
22
|
+
require 'loggable'
|
23
|
+
|
24
|
+
class MyClass; end
|
25
|
+
|
26
|
+
MyClass.logger = Logger.new('debug.log')
|
27
|
+
|
28
|
+
Now, any class or instance methods have access to the logger:
|
29
|
+
|
30
|
+
class MyClass
|
31
|
+
def self.do_something
|
32
|
+
logger.debug 'doing something in the class'
|
33
|
+
end
|
34
|
+
|
35
|
+
def do_something
|
36
|
+
logger.debug 'doing something in an instance'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
The above code will write into the log file when called:
|
41
|
+
|
42
|
+
MyClass.do_something
|
43
|
+
MyClass.new.do_something
|
44
|
+
|
45
|
+
debug.log:
|
46
|
+
|
47
|
+
D, [2008-04-24T20:37:32.273930 #25821] DEBUG -- : doing something in the class
|
48
|
+
D, [2008-04-24T20:37:32.274062 #25821] DEBUG -- : doing something in an instance
|
49
|
+
|
50
|
+
== Removing Logger Functionality
|
51
|
+
|
52
|
+
Calling the <tt>logger=</tt> class method to assign a logger to the class will
|
53
|
+
trigger the methods necessary to start logging messages. If you want to turn off
|
54
|
+
logging temporarily (without removing the logging statements from your class),
|
55
|
+
comment out the line where you assign the new logger. By default, the logger is
|
56
|
+
stubbed out, so any calls to methods on it will just return nil.
|
57
|
+
|
58
|
+
== Credits
|
59
|
+
|
60
|
+
Copyright (c) 2008 Patrick Reagan of Viget Labs (mailto:patrick.reagan@viget.com)
|
61
|
+
|
62
|
+
Permission is hereby granted, free of charge, to any person
|
63
|
+
obtaining a copy of this software and associated documentation
|
64
|
+
files (the "Software"), to deal in the Software without
|
65
|
+
restriction, including without limitation the rights to use,
|
66
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
67
|
+
copies of the Software, and to permit persons to whom the
|
68
|
+
Software is furnished to do so, subject to the following
|
69
|
+
conditions:
|
70
|
+
|
71
|
+
The above copyright notice and this permission notice shall be
|
72
|
+
included in all copies or substantial portions of the Software.
|
73
|
+
|
74
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
75
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
76
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
77
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
78
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
79
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
80
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
81
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -4,41 +4,35 @@ require 'rake/testtask'
|
|
4
4
|
|
5
5
|
require 'lib/loggable/version'
|
6
6
|
|
7
|
-
GEM = "loggable"
|
8
|
-
AUTHOR = "Patrick Reagan"
|
9
|
-
EMAIL = "patrick.reagan@viget.com"
|
10
|
-
HOMEPAGE = "http://viget.rubyforge.org/loggable"
|
11
|
-
SUMMARY = "A gem that provides logging capabilities to any class"
|
12
|
-
|
13
7
|
task :default => :test
|
14
8
|
|
15
9
|
spec = Gem::Specification.new do |s|
|
16
|
-
s.name
|
17
|
-
s.version
|
18
|
-
s.
|
19
|
-
s.
|
20
|
-
s.
|
21
|
-
s.summary
|
22
|
-
s.
|
23
|
-
s.
|
24
|
-
s.
|
25
|
-
s.homepage = HOMEPAGE
|
10
|
+
s.name = 'loggable'
|
11
|
+
s.version = Loggable::Version.to_s
|
12
|
+
s.has_rdoc = true
|
13
|
+
s.extra_rdoc_files = %w(README.rdoc)
|
14
|
+
s.rdoc_options = %w(--main README.rdoc)
|
15
|
+
s.summary = "A gem that provides logging capabilities to any class"
|
16
|
+
s.author = 'Patrick Reagan'
|
17
|
+
s.email = 'patrick.reagan@viget.com'
|
18
|
+
s.homepage = 'http://viget.com/extend'
|
26
19
|
s.rubyforge_project = 'viget'
|
27
|
-
|
28
|
-
s.require_path = 'lib'
|
29
|
-
s.files = %w(LICENSE README HISTORY Rakefile) + Dir.glob("{lib,test}/**/*")
|
20
|
+
s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
|
30
21
|
end
|
31
22
|
|
32
23
|
Rake::GemPackageTask.new(spec) do |pkg|
|
33
24
|
pkg.gem_spec = spec
|
34
25
|
end
|
35
26
|
|
36
|
-
task :install => [:package] do
|
37
|
-
sh %{sudo gem install pkg/#{GEM}-#{VERSION}}
|
38
|
-
end
|
39
|
-
|
40
27
|
Rake::TestTask.new do |t|
|
41
28
|
t.libs << 'test'
|
42
|
-
t.
|
29
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
43
30
|
t.verbose = true
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Generate the gemspec to serve this Gem from Github'
|
34
|
+
task :github do
|
35
|
+
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
36
|
+
File.open(file, 'w') {|f| f << spec.to_ruby }
|
37
|
+
puts "Created gemspec: #{file}"
|
44
38
|
end
|
data/lib/loggable.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
1
3
|
require 'loggable/log_methods'
|
2
4
|
require 'loggable/logger_stub'
|
3
5
|
|
4
|
-
Object
|
5
|
-
|
6
|
+
class Object
|
7
|
+
include Loggable::InstanceMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
class Class
|
11
|
+
include Loggable::ClassMethods
|
12
|
+
end
|
13
|
+
|
14
|
+
class Module
|
15
|
+
include Loggable::ClassMethods
|
16
|
+
end
|
data/lib/loggable/log_methods.rb
CHANGED
@@ -6,7 +6,7 @@ module Loggable
|
|
6
6
|
|
7
7
|
# Use this method on any of your classes to trigger the logging facility:
|
8
8
|
#
|
9
|
-
# MyClass.logger = Logger.new('/path/to/logfile)
|
9
|
+
# MyClass.logger = Logger.new('/path/to/logfile')
|
10
10
|
#
|
11
11
|
# Now you can call the 'logger' method inside a class or instance method to log at
|
12
12
|
# the specified level. See the README for details.
|
data/lib/loggable/version.rb
CHANGED
@@ -6,12 +6,18 @@ class MyClass
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
+
module MyModule; end
|
10
|
+
|
9
11
|
describe "MyClass, with loggable mix-in" do
|
10
12
|
|
11
13
|
before(:each) do
|
12
14
|
@logger = mock()
|
13
15
|
end
|
14
16
|
|
17
|
+
after(:each) do
|
18
|
+
MyClass.logger = nil
|
19
|
+
end
|
20
|
+
|
15
21
|
it "should have a logger stub by default" do
|
16
22
|
MyClass.logger.should.be.an.instance_of(LoggerStub)
|
17
23
|
end
|
@@ -31,4 +37,18 @@ describe "MyClass, with loggable mix-in" do
|
|
31
37
|
MyClass.new.logger.should.equal @logger
|
32
38
|
end
|
33
39
|
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "MyModule, with loggable mix-in" do
|
43
|
+
|
44
|
+
it "should have a logger stub by default" do
|
45
|
+
MyModule.logger.should.be.an.instance_of(LoggerStub)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should be able to log messages" do
|
49
|
+
logger = mock {|m| m.expects(:debug).with('blip') }
|
50
|
+
MyModule.logger = logger
|
51
|
+
MyModule.logger.debug('blip')
|
52
|
+
end
|
53
|
+
|
34
54
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loggable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Reagan
|
@@ -9,23 +9,20 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-21 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description:
|
16
|
+
description:
|
17
17
|
email: patrick.reagan@viget.com
|
18
18
|
executables: []
|
19
19
|
|
20
20
|
extensions: []
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
|
-
- README
|
24
|
-
- LICENSE
|
23
|
+
- README.rdoc
|
25
24
|
files:
|
26
|
-
-
|
27
|
-
- README
|
28
|
-
- HISTORY
|
25
|
+
- README.rdoc
|
29
26
|
- Rakefile
|
30
27
|
- lib/loggable
|
31
28
|
- lib/loggable/log_methods.rb
|
@@ -37,10 +34,11 @@ files:
|
|
37
34
|
- test/examples/logger_stub_test.rb
|
38
35
|
- test/test_helper.rb
|
39
36
|
has_rdoc: true
|
40
|
-
homepage: http://viget.
|
37
|
+
homepage: http://viget.com/extend
|
41
38
|
post_install_message:
|
42
|
-
rdoc_options:
|
43
|
-
|
39
|
+
rdoc_options:
|
40
|
+
- --main
|
41
|
+
- README.rdoc
|
44
42
|
require_paths:
|
45
43
|
- lib
|
46
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -58,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
56
|
requirements: []
|
59
57
|
|
60
58
|
rubyforge_project: viget
|
61
|
-
rubygems_version: 1.1
|
59
|
+
rubygems_version: 1.3.1
|
62
60
|
signing_key:
|
63
61
|
specification_version: 2
|
64
62
|
summary: A gem that provides logging capabilities to any class
|
data/HISTORY
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
== 0.1.0 2008-05-09
|
2
|
-
|
3
|
-
* 2 major enhancements:
|
4
|
-
* Changed the API for using the logging functionality (Class.logger=)
|
5
|
-
* Added in a LoggerStub to intercept calls to a non-existent logging facility
|
6
|
-
|
7
|
-
== 0.0.1 2008-04-24
|
8
|
-
|
9
|
-
* 1 major enhancement:
|
10
|
-
* Initial release
|
data/LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2007 YOUR NAME
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
= Loggable
|
2
|
-
|
3
|
-
Loggable is a gem that's designed to add a logging interface to classes that don't
|
4
|
-
automatically support it.
|
5
|
-
|
6
|
-
== Installation
|
7
|
-
|
8
|
-
This code is available as a Ruby Gem:
|
9
|
-
|
10
|
-
sudo gem install loggable
|
11
|
-
|
12
|
-
== Usage
|
13
|
-
|
14
|
-
Using the Gem is easy, just assign a new logger to your class:
|
15
|
-
|
16
|
-
require 'rubygems'
|
17
|
-
require 'logger'
|
18
|
-
require 'loggable'
|
19
|
-
|
20
|
-
class MyClass; end
|
21
|
-
|
22
|
-
MyClass.logger = Logger.new('debug.log')
|
23
|
-
|
24
|
-
Now, any class or instance methods have access to the logger:
|
25
|
-
|
26
|
-
class MyClass
|
27
|
-
def self.do_something
|
28
|
-
logger.debug 'doing something in the class'
|
29
|
-
end
|
30
|
-
|
31
|
-
def do_something
|
32
|
-
logger.debug 'doing something in an instance'
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
The above code will write into the log file when called:
|
37
|
-
|
38
|
-
MyClass.do_something
|
39
|
-
MyClass.new.do_something
|
40
|
-
|
41
|
-
debug.log:
|
42
|
-
|
43
|
-
D, [2008-04-24T20:37:32.273930 #25821] DEBUG -- : doing something in the class
|
44
|
-
D, [2008-04-24T20:37:32.274062 #25821] DEBUG -- : doing something in an instance
|
45
|
-
|
46
|
-
== Removing Logger Functionality
|
47
|
-
|
48
|
-
Calling the <tt>logger=</tt> class method to assign a logger to the class will
|
49
|
-
trigger the methods necessary to start logging messages. If you want to turn off
|
50
|
-
logging temporarily (without removing the logging statements from your class),
|
51
|
-
comment out the line where you assign the new logger. By default, the logger is
|
52
|
-
stubbed out, so any calls to methods on it will just return nil.
|
53
|
-
|
54
|
-
== Credits
|
55
|
-
|
56
|
-
Copyright (c) 2008 Patrick Reagan of Viget Labs (mailto:patrick.reagan@viget.com)
|
57
|
-
Released under the MIT license
|