taglog 0.0.1 → 0.0.2
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/lib/taglog.rb +16 -9
- data/lib/taglog/version.rb +1 -1
- data/spec/taglog_spec.rb +13 -3
- metadata +3 -3
data/lib/taglog.rb
CHANGED
|
@@ -29,25 +29,32 @@ class Taglog < Module
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
LEVELS.each do |level|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
class_eval %Q{
|
|
33
|
+
def #{level}(arg=nil, &block)
|
|
34
|
+
if block_given?
|
|
35
|
+
delegate(:#{level}, arg) { tagged(block.call) }
|
|
36
|
+
else
|
|
37
|
+
delegate(:#{level}, tagged(arg))
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
}
|
|
35
41
|
end
|
|
36
42
|
|
|
37
|
-
def method_missing(name, *args)
|
|
38
|
-
delegate(name, *args)
|
|
43
|
+
def method_missing(name, *args, &block)
|
|
44
|
+
delegate(name, *args, &block)
|
|
39
45
|
end
|
|
40
46
|
|
|
41
|
-
private
|
|
42
|
-
|
|
43
47
|
attr_reader :context, :tag
|
|
48
|
+
private :context, :tag
|
|
49
|
+
|
|
50
|
+
private
|
|
44
51
|
|
|
45
52
|
def tagged(message)
|
|
46
53
|
"[#{tag}] #{message}"
|
|
47
54
|
end
|
|
48
55
|
|
|
49
|
-
def delegate(method_name, *args)
|
|
50
|
-
logger.send(method_name, *args)
|
|
56
|
+
def delegate(method_name, *args, &block)
|
|
57
|
+
logger.send(method_name, *args, &block)
|
|
51
58
|
end
|
|
52
59
|
|
|
53
60
|
def logger
|
data/lib/taglog/version.rb
CHANGED
data/spec/taglog_spec.rb
CHANGED
|
@@ -18,7 +18,7 @@ describe Taglog do
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
let(:formatter) do
|
|
21
|
-
proc {|_, _,
|
|
21
|
+
proc {|_, _, program_name, message| "#{program_name}: #{message}" }
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
let(:io) do
|
|
@@ -44,9 +44,19 @@ describe Taglog do
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
describe "#info" do
|
|
47
|
-
it "is wrapped by tag" do
|
|
47
|
+
it "is wrapped by tag for an argument" do
|
|
48
48
|
klass.new.logger.info("message")
|
|
49
|
-
result.should == "[tag] message"
|
|
49
|
+
result.should == ": [tag] message"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "is wrapped by tag for return value of block" do
|
|
53
|
+
klass.new.logger.info { "block" + "message" }
|
|
54
|
+
result.should == ": [tag] blockmessage"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "is wrapped by tag for an argument with return value of block" do
|
|
58
|
+
klass.new.logger.info("program_name") { "block" + "message" }
|
|
59
|
+
result.should == "program_name: [tag] blockmessage"
|
|
50
60
|
end
|
|
51
61
|
end
|
|
52
62
|
|
metadata
CHANGED