yell 0.13.0 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +32 -0
- data/lib/yell/level.rb +1 -1
- data/lib/yell/logger.rb +12 -2
- data/lib/yell/version.rb +1 -1
- data/spec/yell/logger_spec.rb +10 -0
- data/spec/yell/repository_spec.rb +8 -0
- data/spec/yell_spec.rb +23 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -74,6 +74,38 @@ logger = Yell.new do |l|
|
|
74
74
|
end
|
75
75
|
```
|
76
76
|
|
77
|
+
### But I'm used to Log4r and I don't want to move on
|
78
|
+
|
79
|
+
One of the really nice features of Log4r is its repository. The following example is
|
80
|
+
taken from the official Log4r [documentation](http://log4r.rubyforge.org/manual.html#outofbox).
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
require 'log4r'
|
84
|
+
include Log4r
|
85
|
+
|
86
|
+
# create a logger named 'mylog' that logs to stdout
|
87
|
+
mylog = Logger.new 'mylog'
|
88
|
+
mylog.outputters = Outputter.stdout
|
89
|
+
|
90
|
+
# later in the code, you can get the logger back
|
91
|
+
Logger['mylog']
|
92
|
+
```
|
93
|
+
|
94
|
+
With Yell you can do the same thing with less:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
require 'yell'
|
98
|
+
|
99
|
+
# create a logger named 'mylog' that logs to stdout
|
100
|
+
Yell.new :stdout, :name => 'mylog'
|
101
|
+
|
102
|
+
# later in the code, you can get the logger back
|
103
|
+
Yell['mylog']
|
104
|
+
```
|
105
|
+
|
106
|
+
There is no need to define outputters separately and you don't have to taint
|
107
|
+
you global namespace with Yell's subclasses.
|
108
|
+
|
77
109
|
|
78
110
|
## Further Readings
|
79
111
|
|
data/lib/yell/level.rb
CHANGED
@@ -32,7 +32,7 @@ module Yell #:nodoc:
|
|
32
32
|
# @example Set the level to :warn
|
33
33
|
# level = :warn
|
34
34
|
#
|
35
|
-
# @param [String, Symbol, Integer]
|
35
|
+
# @param [String, Symbol, Integer] severity The minimum log level
|
36
36
|
def level=( severity )
|
37
37
|
@level = case severity
|
38
38
|
when Yell::Level then severity
|
data/lib/yell/logger.rb
CHANGED
@@ -9,6 +9,9 @@ module Yell #:nodoc:
|
|
9
9
|
class Logger
|
10
10
|
include Yell::Level::Helpers
|
11
11
|
|
12
|
+
# The name of the logger instance
|
13
|
+
attr_reader :name
|
14
|
+
|
12
15
|
# Initialize a new Logger
|
13
16
|
#
|
14
17
|
# @example A standard file logger
|
@@ -48,14 +51,17 @@ module Yell #:nodoc:
|
|
48
51
|
# set the log level when given
|
49
52
|
self.level = @options[:level]
|
50
53
|
|
54
|
+
# set the loggeer's name
|
55
|
+
self.name = @options[:name] if @options[:name]
|
56
|
+
|
51
57
|
# extract adapter
|
52
|
-
adapter args.pop if args.any?
|
58
|
+
self.adapter args.pop if args.any?
|
53
59
|
|
54
60
|
# eval the given block
|
55
61
|
_call( &block ) if block
|
56
62
|
|
57
63
|
# default adapter when none defined
|
58
|
-
adapter :file if @adapters.empty?
|
64
|
+
self.adapter :file if @adapters.empty?
|
59
65
|
end
|
60
66
|
|
61
67
|
# Define an adapter to be used for logging.
|
@@ -88,6 +94,10 @@ module Yell #:nodoc:
|
|
88
94
|
@adapters << Yell::Adapters.new( type, options, &block )
|
89
95
|
end
|
90
96
|
|
97
|
+
def name=( val )
|
98
|
+
Yell::Repository[val] = self
|
99
|
+
end
|
100
|
+
|
91
101
|
# Deprecated: Use attr_reader in future
|
92
102
|
def level( val = nil )
|
93
103
|
if val.nil?
|
data/lib/yell/version.rb
CHANGED
data/spec/yell/logger_spec.rb
CHANGED
@@ -47,6 +47,16 @@ describe Yell::Logger do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
context "initialize with a :name" do
|
51
|
+
let( :name ) { 'test' }
|
52
|
+
|
53
|
+
it "should be added to the repository" do
|
54
|
+
logger = Yell.new :name => name
|
55
|
+
|
56
|
+
Yell::Repository[name].should == logger
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
50
60
|
context "initialize with a :filename" do
|
51
61
|
it "should call adapter with :file" do
|
52
62
|
mock.proxy( Yell::Adapters::File ).new( :filename => 'test.log' )
|
data/spec/yell_spec.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Yell do
|
4
|
-
|
4
|
+
let( :logger ) { Yell.new }
|
5
|
+
|
6
|
+
subject { logger }
|
5
7
|
|
6
8
|
it { should be_kind_of Yell::Logger }
|
7
9
|
|
@@ -31,5 +33,25 @@ describe Yell do
|
|
31
33
|
it { should be_kind_of Yell::Logger }
|
32
34
|
end
|
33
35
|
|
36
|
+
context :[] do
|
37
|
+
let( :name ) { 'test' }
|
38
|
+
|
39
|
+
it "should delegate to the repository" do
|
40
|
+
mock( Yell::Repository )[ name ]
|
41
|
+
|
42
|
+
Yell[ name ]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context :[]= do
|
47
|
+
let( :name ) { 'test' }
|
48
|
+
|
49
|
+
it "should delegate to the repository" do
|
50
|
+
mock.proxy( Yell::Repository )[name] = logger
|
51
|
+
|
52
|
+
Yell[ name ] = logger
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
34
56
|
end
|
35
57
|
|