lager 0.2.0.4 → 0.2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/MANIFEST.txt +3 -0
- data/VERSION +1 -1
- data/examples/foo.rb +36 -0
- data/examples/usage.rb +40 -0
- data/test/lager.rb +68 -0
- metadata +4 -1
data/MANIFEST.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.0.
|
1
|
+
0.2.0.5
|
data/examples/foo.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative '../lib/lager'
|
2
|
+
|
3
|
+
class Foo
|
4
|
+
extend Lager
|
5
|
+
|
6
|
+
# set logging from within, useful for default behavior
|
7
|
+
#
|
8
|
+
log_to $stdout, :warn
|
9
|
+
|
10
|
+
def self.bar
|
11
|
+
@lager.debug { "inside Foo.bar" }
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
# assign @lager at the instance layer if you want to use it
|
16
|
+
# @lager, here, is technically a different variable than used above
|
17
|
+
# though we are setting them to the same thing
|
18
|
+
#
|
19
|
+
@lager = self.class.lager
|
20
|
+
@lager.debug { "inside Foo#initialize" }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
if __FILE__ == $0
|
25
|
+
Foo.bar
|
26
|
+
Foo.new
|
27
|
+
|
28
|
+
# set logging from outside
|
29
|
+
#
|
30
|
+
puts "Turning on debug logging"
|
31
|
+
Foo.log_to $stderr
|
32
|
+
Foo.log_level :debug
|
33
|
+
|
34
|
+
Foo.bar
|
35
|
+
Foo.new
|
36
|
+
end
|
data/examples/usage.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative '../lib/lager'
|
2
|
+
|
3
|
+
class Foo
|
4
|
+
extend Lager
|
5
|
+
log_to $stdout, :debug # sets up @lager at the class layer
|
6
|
+
|
7
|
+
def self.bar(baz)
|
8
|
+
unless baz.is_a?(String)
|
9
|
+
@lager.debug { "baz #{baz} is a #{baz.class}, not a string" }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
# set the instance layer's @lager to the class layer's @lager
|
15
|
+
@lager = self.class.lager
|
16
|
+
# now both layers are using the same instance
|
17
|
+
end
|
18
|
+
|
19
|
+
def do_something_complicated
|
20
|
+
@lager.debug { "about to do something complicated" }
|
21
|
+
# ...
|
22
|
+
@lager.debug { "whew! we made it!" }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if __FILE__ == $0
|
27
|
+
puts "About to spew debug messages"
|
28
|
+
Foo.bar(15)
|
29
|
+
f = Foo.new
|
30
|
+
f.do_something_complicated
|
31
|
+
|
32
|
+
puts "Now updating Foo's log level"
|
33
|
+
Foo.log_level :warn
|
34
|
+
Foo.new.do_something_complicated
|
35
|
+
|
36
|
+
puts "Now the same calls as before"
|
37
|
+
Foo.bar(15)
|
38
|
+
f = Foo.new
|
39
|
+
f.do_something_complicated
|
40
|
+
end
|
data/test/lager.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
require_relative '../lib/lager'
|
7
|
+
require_relative '../examples/foo' # useful Foo class
|
8
|
+
|
9
|
+
describe Lager do
|
10
|
+
describe ".version" do
|
11
|
+
it "must return a string of numbers and dots" do
|
12
|
+
Lager.version.must_match %r{\A[0-9\.]+\z}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#log_to" do
|
17
|
+
it "must have created a Logger" do
|
18
|
+
# note, the useful Foo class has already called log_to in the class def
|
19
|
+
Foo.lager.must_be_instance_of(Logger)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "must return nil" do
|
23
|
+
Foo.log_to.must_be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it "must use an existing Logger when provided" do
|
27
|
+
l = Logger.new($stderr)
|
28
|
+
Foo.log_to l
|
29
|
+
Foo.lager.must_equal l
|
30
|
+
Foo.log_level :info
|
31
|
+
Foo.bar # does debug logging, should be silent
|
32
|
+
Foo.lager.must_equal l
|
33
|
+
end
|
34
|
+
|
35
|
+
it "must handle a Tempfile when provided" do
|
36
|
+
t = Tempfile.new('lager')
|
37
|
+
Foo.log_to t
|
38
|
+
Foo.log_level :debug
|
39
|
+
Foo.bar # does debug logging
|
40
|
+
t.rewind
|
41
|
+
t.read.wont_be_empty
|
42
|
+
t.close
|
43
|
+
t.unlink
|
44
|
+
end
|
45
|
+
|
46
|
+
it "must handle a path to /tmp when provided" do
|
47
|
+
fname = '/tmp/lager.log'
|
48
|
+
Foo.log_to fname
|
49
|
+
Foo.log_level :debug
|
50
|
+
Foo.bar # does debug logging
|
51
|
+
Foo.log_to $stderr
|
52
|
+
File.exists?(fname).must_equal true
|
53
|
+
File.unlink fname
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#log_level" do
|
58
|
+
it "must accept :debug as Logger::DEBUG" do
|
59
|
+
Foo.log_level :debug
|
60
|
+
Foo.log_level.must_equal Logger::DEBUG
|
61
|
+
end
|
62
|
+
|
63
|
+
it "must accept Logger::INFO as Logger::INFO" do
|
64
|
+
Foo.log_level Logger::INFO
|
65
|
+
Foo.log_level.must_equal Logger::INFO
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.0.
|
4
|
+
version: 0.2.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -54,6 +54,9 @@ files:
|
|
54
54
|
- README.md
|
55
55
|
- rakefile.rb
|
56
56
|
- lib/lager.rb
|
57
|
+
- test/lager.rb
|
58
|
+
- examples/foo.rb
|
59
|
+
- examples/usage.rb
|
57
60
|
homepage: http://github.com/rickhull/lager
|
58
61
|
licenses:
|
59
62
|
- LGPL
|