simple_logger 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/MIT-LICENSE +19 -0
- data/README.textile +38 -0
- data/Rakefile +16 -0
- data/VERSION +1 -0
- data/lib/simple_logger.rb +27 -0
- data/simple_logger.gemspec +47 -0
- data/test/simple_logger_test.rb +44 -0
- metadata +62 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2009 Capital Thought.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
h1. Simple Logger
|
2
|
+
|
3
|
+
Including this module equips your object with class- and instance-level references to a logger that uses intelligent defaults. If no logger is present, we look for the Rails default logger (Rails.logger). If all else fails, the code instantiates a new logger pointed at STDOUT.
|
4
|
+
|
5
|
+
h2. Usage
|
6
|
+
|
7
|
+
require 'simple_logger'
|
8
|
+
|
9
|
+
class Foo
|
10
|
+
include SimpleLogger
|
11
|
+
end
|
12
|
+
|
13
|
+
>> f = Foo.new
|
14
|
+
=> #<Foo:0x1017f0e48>
|
15
|
+
>> f.logger
|
16
|
+
=> #<Logger:0x1017fe1d8 ... >
|
17
|
+
>> Foo.logger
|
18
|
+
=> #<Logger:0x1017fe1d8 ... >
|
19
|
+
>> f.logger = Logger.new(STDERR)
|
20
|
+
=> #<Logger:0x1017d0f08 ... >
|
21
|
+
>> f.logger != Foo.logger
|
22
|
+
=> true
|
23
|
+
|
24
|
+
h3. Patches
|
25
|
+
|
26
|
+
Accepted via GitHub.
|
27
|
+
|
28
|
+
h4. Author
|
29
|
+
|
30
|
+
Written by Mike Subelsky (mike@subelsky.com).
|
31
|
+
|
32
|
+
h5. Warranty
|
33
|
+
|
34
|
+
No warranty whatsoever. But please enjoy!
|
35
|
+
|
36
|
+
h6. Copyright
|
37
|
+
|
38
|
+
Copyright (c) 2009 Capital Thought (http://capitalthought.com), released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "simple_logger"
|
5
|
+
gemspec.summary = "Easy class- and instance-level logging"
|
6
|
+
gemspec.description = "Including this module equips your object with class- and instance-level references to a logger that uses intelligent defaults. If no logger is present, we look for the Rails default logger (Rails.logger). If all else fails, the code instantiates a new logger pointed at STDOUT."
|
7
|
+
gemspec.email = "mike@otherinbox.com"
|
8
|
+
gemspec.homepage = "http://github.com/otherinbox/simple_logger"
|
9
|
+
gemspec.authors = ["Mike Subelsky"]
|
10
|
+
gemspec.test_files = %w(test/simple_logger_test.rb)
|
11
|
+
end
|
12
|
+
|
13
|
+
Jeweler::GemcutterTasks.new
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
16
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module SimpleLogger
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def logger
|
11
|
+
@logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
12
|
+
end
|
13
|
+
|
14
|
+
def logger=(l)
|
15
|
+
@logger = l
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def logger
|
20
|
+
@logger ||= self.class.logger
|
21
|
+
end
|
22
|
+
|
23
|
+
def logger=(l)
|
24
|
+
@logger = l
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{simple_logger}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Mike Subelsky"]
|
12
|
+
s.date = %q{2010-01-04}
|
13
|
+
s.description = %q{Including this module equips your object with class- and instance-level references to a logger that uses intelligent defaults. If no logger is present, we look for the Rails default logger (Rails.logger). If all else fails, the code instantiates a new logger pointed at STDOUT.}
|
14
|
+
s.email = %q{mike@otherinbox.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.textile"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"MIT-LICENSE",
|
21
|
+
"README.textile",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"lib/simple_logger.rb",
|
25
|
+
"simple_logger.gemspec",
|
26
|
+
"test/simple_logger_test.rb"
|
27
|
+
]
|
28
|
+
s.homepage = %q{http://github.com/otherinbox/simple_logger}
|
29
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
s.rubygems_version = %q{1.3.5}
|
32
|
+
s.summary = %q{Easy class- and instance-level logging}
|
33
|
+
s.test_files = [
|
34
|
+
"test/simple_logger_test.rb"
|
35
|
+
]
|
36
|
+
|
37
|
+
if s.respond_to? :specification_version then
|
38
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
39
|
+
s.specification_version = 3
|
40
|
+
|
41
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
42
|
+
else
|
43
|
+
end
|
44
|
+
else
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'ostruct'
|
3
|
+
require File.join(File.dirname(__FILE__),'..','lib','simple_logger')
|
4
|
+
|
5
|
+
class TestLogger < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_class_sets_a_default_logger
|
8
|
+
a = Class.new { include SimpleLogger }
|
9
|
+
assert_not_nil a.logger
|
10
|
+
assert_instance_of Logger, a.logger
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_class_uses_rails_logger_if_present
|
14
|
+
logger = Logger.new(STDOUT)
|
15
|
+
Object.instance_eval { const_set :Rails, OpenStruct.new(:logger => logger) }
|
16
|
+
a = Class.new { include SimpleLogger }
|
17
|
+
assert_equal logger,a.logger
|
18
|
+
Object.instance_eval { remove_const :Rails }
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_can_override_default_logger
|
22
|
+
a = Class.new { include SimpleLogger }
|
23
|
+
l = Logger.new(STDERR)
|
24
|
+
a.logger = l
|
25
|
+
assert_equal l, a.logger
|
26
|
+
end
|
27
|
+
|
28
|
+
class Foo
|
29
|
+
include SimpleLogger
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_instance_uses_class_logger_by_default
|
33
|
+
instance = Foo.new
|
34
|
+
assert_equal instance.logger, Foo.logger
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_instance_uses_own_logger_if_specified
|
38
|
+
instance = Foo.new
|
39
|
+
l = Logger.new(STDERR)
|
40
|
+
instance.logger = l
|
41
|
+
assert_equal l, instance.logger
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Subelsky
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-04 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Including this module equips your object with class- and instance-level references to a logger that uses intelligent defaults. If no logger is present, we look for the Rails default logger (Rails.logger). If all else fails, the code instantiates a new logger pointed at STDOUT.
|
17
|
+
email: mike@otherinbox.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.textile
|
24
|
+
files:
|
25
|
+
- .gitignore
|
26
|
+
- MIT-LICENSE
|
27
|
+
- README.textile
|
28
|
+
- Rakefile
|
29
|
+
- VERSION
|
30
|
+
- lib/simple_logger.rb
|
31
|
+
- simple_logger.gemspec
|
32
|
+
- test/simple_logger_test.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/otherinbox/simple_logger
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options:
|
39
|
+
- --charset=UTF-8
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.3.5
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Easy class- and instance-level logging
|
61
|
+
test_files:
|
62
|
+
- test/simple_logger_test.rb
|