low 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,48 +1,25 @@
1
1
  require 'logger'
2
2
 
3
3
  module Low
4
- # `Low::ScopedLogger` is a tiny wrapper around `Logger`. It allows
4
+ # `Low::ScopedLogger` is a tiny extension to `Logger`. It allows
5
5
  # `scope` to be specified, making it easy to grep any messages generated
6
6
  # by a particular instance.
7
- class ScopedLogger
7
+ class ScopedLogger < Logger
8
8
  attr_accessor :scope
9
9
 
10
- def initialize(io = $stdout)
11
- @logger = ::Logger.new(io)
12
- end
13
-
14
- def level=(level)
15
- @logger.level = level
16
- end
17
-
18
- def level
19
- @logger.level
20
- end
21
-
22
- def fatal(message = nil, progname = nil, &block)
23
- add ::Logger::FATAL, message, progname, &block
24
- end
25
-
26
- def error(message = nil, progname = nil, &block)
27
- add ::Logger::ERROR, message, progname, &block
28
- end
29
-
30
- def warn(message = nil, progname = nil, &block)
31
- add ::Logger::WARN, message, progname, &block
32
- end
33
-
34
- def info(message = nil, progname = nil, &block)
35
- add ::Logger::INFO, message, progname, &block
36
- end
37
-
38
- def debug(message = nil, progname = nil, &block)
39
- add ::Logger::DEBUG, message, progname, &block
40
- end
10
+ def add(severity, message = nil, progname = nil, &block)
11
+ if message.nil?
12
+ if block_given?
13
+ message = yield
14
+ else
15
+ message = progname
16
+ progname = @progname
17
+ end
18
+ end
41
19
 
42
- def add(level, message = nil, progname = nil, &block)
43
20
  formatted_message = message
44
21
  formatted_message = "[#{@scope}] #{formatted_message}" if @scope
45
- @logger.add level, formatted_message, progname, &block
22
+ super severity, formatted_message, progname, &block
46
23
  end
47
24
  end
48
25
  end
data/lib/low/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Low
2
- VERSION = '0.0.11'
2
+ VERSION = '0.0.12'
3
3
  end
@@ -82,5 +82,16 @@ describe Low::ScopedLogger do
82
82
  message.should =~ /abc123/
83
83
  message.should =~ /Yadda$/
84
84
  end
85
+
86
+ it 'should append the key if the message is specified in a block' do
87
+ io = StringIO.new
88
+ logger = Low::ScopedLogger.new(io)
89
+ logger.scope = 'abc123'
90
+ logger.info { 'Yadda' }
91
+
92
+ io.rewind; message = io.read
93
+ message.should =~ /abc123/
94
+ message.should =~ /Yadda$/
95
+ end
85
96
  end
86
97
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: low
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-13 00:00:00.000000000 Z
12
+ date: 2012-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack