buffered_logger 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/buffered_logger/formatting.rb +9 -5
- data/spec/formatting_spec.rb +3 -3
- metadata +4 -4
@@ -71,7 +71,7 @@ class BufferedLogger::Formatter
|
|
71
71
|
|
72
72
|
def %(message)
|
73
73
|
formatted_message = @format % message.to_s
|
74
|
-
|
74
|
+
parse_color(formatted_message)
|
75
75
|
end
|
76
76
|
|
77
77
|
private
|
@@ -81,11 +81,15 @@ private
|
|
81
81
|
color_matcher = /#{color_methods.map {|m| "\\$#{m}\\s?"}.join('|')}/
|
82
82
|
|
83
83
|
strings = message.split(color_matcher)
|
84
|
-
|
84
|
+
if color?
|
85
|
+
colors = message.scan(color_matcher).map { |c| c[1..-1].strip }
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
87
|
+
colored_message = ''
|
88
|
+
strings[1..-1].each_with_index { |s,i| colored_message << self.send(colors[i], s) }
|
89
|
+
strings[0] + colored_message
|
90
|
+
else
|
91
|
+
strings.join('')
|
92
|
+
end
|
89
93
|
end
|
90
94
|
|
91
95
|
end
|
data/spec/formatting_spec.rb
CHANGED
@@ -77,7 +77,7 @@ describe BufferedLogger do
|
|
77
77
|
@l.info "haha"
|
78
78
|
|
79
79
|
# colors are off so the keywords won't be parsed
|
80
|
-
@f.string.should == "
|
80
|
+
@f.string.should == "oh\nblah\nhey\nhaha\n"
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'should use appropriate formatting for each severity level' do
|
@@ -85,7 +85,7 @@ describe BufferedLogger do
|
|
85
85
|
@l.send(:set_formatter, :info, "$blue %s")
|
86
86
|
@l.error 'error'
|
87
87
|
@l.info 'info'
|
88
|
-
@f.string.should == "
|
88
|
+
@f.string.should == "error\ninfo\n"
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'should use the master thread formatter if one isnt set' do
|
@@ -95,7 +95,7 @@ describe BufferedLogger do
|
|
95
95
|
t = Thread.new do
|
96
96
|
@l.error 'blah'
|
97
97
|
end; t.join
|
98
|
-
@f.string.should == "
|
98
|
+
@f.string.should == "test\nblah\n"
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'should use the master thread default formatter if one isnt set' do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buffered_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alex Skryl
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-20 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|