yell 0.8.0 → 0.9.0
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/yell.rb +6 -0
- data/lib/yell/adapters.rb +2 -2
- data/lib/yell/adapters/io.rb +0 -2
- data/lib/yell/configuration.rb +17 -0
- data/lib/yell/level.rb +12 -2
- data/lib/yell/logger.rb +22 -3
- data/lib/yell/version.rb +1 -1
- data/spec/fixtures/yell.yml +7 -0
- data/spec/yell/adapters_spec.rb +2 -2
- data/spec/yell/configuration_spec.rb +15 -0
- data/spec/yell/level_spec.rb +44 -0
- data/spec/yell/logger_spec.rb +23 -0
- data/spec/yell_spec.rb +15 -2
- metadata +8 -3
data/lib/yell.rb
CHANGED
@@ -52,6 +52,10 @@ module Yell #:nodoc:
|
|
52
52
|
ENV['YELL_ENV'] || ENV['RACK_ENV'] || 'development'
|
53
53
|
end
|
54
54
|
|
55
|
+
def load!( file )
|
56
|
+
Yell.new Yell::Configuration.load!( file )
|
57
|
+
end
|
58
|
+
|
55
59
|
def _deprecate( version, message, options = {} )
|
56
60
|
warning = ["Deprecation Warning (since v#{version}): #{message}" ]
|
57
61
|
warning << " before: #{options[:before]}" if options[:before]
|
@@ -70,3 +74,5 @@ require File.dirname(__FILE__) + '/yell/formatter'
|
|
70
74
|
require File.dirname(__FILE__) + '/yell/adapters'
|
71
75
|
require File.dirname(__FILE__) + '/yell/logger'
|
72
76
|
|
77
|
+
require File.dirname(__FILE__) + '/yell/configuration'
|
78
|
+
|
data/lib/yell/adapters.rb
CHANGED
@@ -4,7 +4,7 @@ module Yell #:nodoc:
|
|
4
4
|
|
5
5
|
# NoSuchAdapter is raised whenever you want to instantiate an
|
6
6
|
# adapter that does not exist.
|
7
|
-
class
|
7
|
+
class UnregisteredAdapter < StandardError; end
|
8
8
|
|
9
9
|
# This module provides the interface to attaching adapters to
|
10
10
|
# the logger. You should not have to call the corresponding classes
|
@@ -35,7 +35,7 @@ module Yell #:nodoc:
|
|
35
35
|
else @@adapters[name]
|
36
36
|
end
|
37
37
|
|
38
|
-
raise
|
38
|
+
raise UnregisteredAdapter.new( name ) unless adapter
|
39
39
|
|
40
40
|
adapter.new( options, &block )
|
41
41
|
end
|
data/lib/yell/adapters/io.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Yell #:nodoc:
|
6
|
+
|
7
|
+
# The Configuration can be used to setup Yell before
|
8
|
+
# initializing an instance.
|
9
|
+
class Configuration
|
10
|
+
|
11
|
+
def self.load!( file )
|
12
|
+
YAML.load( ::File.read(file) )
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
data/lib/yell/level.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Yell #:nodoc:
|
4
|
+
InterpretRegexp = /(at|gt|gte|lt|lte)?\.?(#{Yell::Severities.join('|')}})/i
|
4
5
|
|
5
6
|
# The +Level+ class handles the severities for you in order to determine
|
6
7
|
# if an adapter should log or not.
|
@@ -63,8 +64,9 @@ module Yell #:nodoc:
|
|
63
64
|
|
64
65
|
case severity
|
65
66
|
when Array then at( *severity )
|
66
|
-
when Range then gte(severity.first).lte(severity.last)
|
67
|
-
when Integer,
|
67
|
+
when Range then gte( severity.first ).lte( severity.last )
|
68
|
+
when Integer, Symbol then gte( severity )
|
69
|
+
when String then interpret!( severity )
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
@@ -117,6 +119,14 @@ module Yell #:nodoc:
|
|
117
119
|
|
118
120
|
private
|
119
121
|
|
122
|
+
def interpret!( severities )
|
123
|
+
severities.split( ' ' ).each do |severity|
|
124
|
+
if m = InterpretRegexp.match(severity)
|
125
|
+
m[1].nil? ? __send__( :gte, m[2] ) : __send__( m[1], m[2] )
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
120
130
|
def calculate!( modifier, severity ) #:nodoc:
|
121
131
|
index = index_from( severity )
|
122
132
|
return if index.nil?
|
data/lib/yell/logger.rb
CHANGED
@@ -37,6 +37,9 @@ module Yell #:nodoc:
|
|
37
37
|
# extract options
|
38
38
|
@options = args.last.is_a?(Hash) ? args.pop : {}
|
39
39
|
|
40
|
+
# adapters may be passed in the options
|
41
|
+
_extract_adapters!( @options )
|
42
|
+
|
40
43
|
# check if filename was given as argument and put it into the @options
|
41
44
|
if args.last.is_a?( String )
|
42
45
|
@options[:filename] = args.pop unless @options[:filename]
|
@@ -46,10 +49,9 @@ module Yell #:nodoc:
|
|
46
49
|
self.level = @options[:level]
|
47
50
|
|
48
51
|
# extract adapter
|
49
|
-
|
52
|
+
adapter args.pop if args.any?
|
50
53
|
|
51
54
|
# eval the given block
|
52
|
-
# block.call(self) if block
|
53
55
|
_call( &block ) if block
|
54
56
|
|
55
57
|
# default adapter when none defined
|
@@ -79,7 +81,7 @@ module Yell #:nodoc:
|
|
79
81
|
#
|
80
82
|
# @raise [Yell::NoSuchAdapter] Will be thrown when the adapter is not defined
|
81
83
|
def adapter( type = :file, *args, &block )
|
82
|
-
options = [@options, *args].inject( Hash.new ) do |h,c|
|
84
|
+
options = [@options, *args].inject( Hash.new ) do |h, c|
|
83
85
|
h.merge( c.is_a?(String) ? {:filename => c} : c )
|
84
86
|
end
|
85
87
|
|
@@ -147,6 +149,23 @@ module Yell #:nodoc:
|
|
147
149
|
end
|
148
150
|
end
|
149
151
|
|
152
|
+
# The :adapters key may be passed to the options hash. It may appear in
|
153
|
+
# multiple variations:
|
154
|
+
#
|
155
|
+
# @example
|
156
|
+
# options = { :adapters => [:stdout, :stderr] }
|
157
|
+
#
|
158
|
+
# @example
|
159
|
+
# options = { :adapters => [:stdout => {:level => :info}, :stderr => {:level => :error}]
|
160
|
+
def _extract_adapters!( opts )
|
161
|
+
( opts.delete( :adapters ) || [] ).each do |a|
|
162
|
+
case a
|
163
|
+
when String, Symbol then adapter( a )
|
164
|
+
else a.each { |n, o| adapter( n, o || {} ) }
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
150
169
|
# Cycles all the adapters and writes the message
|
151
170
|
def write( event )
|
152
171
|
@adapters.each { |a| a.write(event) }
|
data/lib/yell/version.rb
CHANGED
data/spec/yell/adapters_spec.rb
CHANGED
@@ -28,8 +28,8 @@ describe Yell::Adapters do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
context "given an unregistered adapter" do
|
31
|
-
it "should raise
|
32
|
-
lambda { Yell::Adapters.new :unknown }.should raise_error Yell::
|
31
|
+
it "should raise UnregisteredAdapter" do
|
32
|
+
lambda { Yell::Adapters.new :unknown }.should raise_error Yell::UnregisteredAdapter
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yell::Configuration do
|
4
|
+
|
5
|
+
describe ":load!" do
|
6
|
+
let( :file ) { File.expand_path File.dirname(__FILE__) + '/../fixtures/yell.yml' }
|
7
|
+
let( :configuration ) { Yell::Configuration.load!( file ) }
|
8
|
+
|
9
|
+
it "should return the hash from the given file" do
|
10
|
+
YAML.load( File.read(file) ).should == configuration
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
data/spec/yell/level_spec.rb
CHANGED
@@ -66,6 +66,50 @@ describe Yell::Level do
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
+
context "given a String" do
|
70
|
+
let( :level ) { Yell::Level.new(subject) }
|
71
|
+
|
72
|
+
context "basic string" do
|
73
|
+
subject { 'error' }
|
74
|
+
|
75
|
+
it { level.at?(:debug).should be_false }
|
76
|
+
it { level.at?(:info).should be_false }
|
77
|
+
it { level.at?(:warn).should be_false }
|
78
|
+
it { level.at?(:error).should be_true }
|
79
|
+
it { level.at?(:fatal).should be_true }
|
80
|
+
end
|
81
|
+
|
82
|
+
context "complex string with outer boundaries" do
|
83
|
+
subject { 'gte.info lte.error' }
|
84
|
+
|
85
|
+
it { level.at?(:debug).should be_false }
|
86
|
+
it { level.at?(:info).should be_true }
|
87
|
+
it { level.at?(:warn).should be_true }
|
88
|
+
it { level.at?(:error).should be_true }
|
89
|
+
it { level.at?(:fatal).should be_false }
|
90
|
+
end
|
91
|
+
|
92
|
+
context "complex string with inner boundaries" do
|
93
|
+
subject { 'gt.info lt.error' }
|
94
|
+
|
95
|
+
it { level.at?(:debug).should be_false }
|
96
|
+
it { level.at?(:info).should be_false }
|
97
|
+
it { level.at?(:warn).should be_true }
|
98
|
+
it { level.at?(:error).should be_false }
|
99
|
+
it { level.at?(:fatal).should be_false }
|
100
|
+
end
|
101
|
+
|
102
|
+
context "complex string with precise boundaries" do
|
103
|
+
subject { 'at.info at.error' }
|
104
|
+
|
105
|
+
it { level.at?(:debug).should be_false }
|
106
|
+
it { level.at?(:info).should be_true }
|
107
|
+
it { level.at?(:warn).should be_false }
|
108
|
+
it { level.at?(:error).should be_true }
|
109
|
+
it { level.at?(:fatal).should be_false }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
69
113
|
context "given an Array" do
|
70
114
|
let( :level ) { Yell::Level.new( [:debug, :warn, :fatal] ) }
|
71
115
|
|
data/spec/yell/logger_spec.rb
CHANGED
@@ -106,6 +106,29 @@ describe Yell::Logger do
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
+
context "initialize with :adapters option" do
|
110
|
+
let( :logger ) do
|
111
|
+
Yell::Logger.new :adapters => [ :stdout, { :stderr => {:level => :error} } ]
|
112
|
+
end
|
113
|
+
|
114
|
+
let( :adapters ) { logger.instance_variable_get :@adapters }
|
115
|
+
let( :stdout ) { adapters.first }
|
116
|
+
let( :stderr ) { adapters.last }
|
117
|
+
|
118
|
+
it "should define those adapters" do
|
119
|
+
adapters.size.should == 2
|
120
|
+
|
121
|
+
stdout.should be_kind_of Yell::Adapters::Stdout
|
122
|
+
stderr.should be_kind_of Yell::Adapters::Stderr
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should pass :level to :stderr adapter" do
|
126
|
+
stderr.level.at?(:warn).should be_false
|
127
|
+
stderr.level.at?(:error).should be_true
|
128
|
+
stderr.level.at?(:fatal).should be_true
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
109
132
|
context "caller's :file, :line and :method" do
|
110
133
|
let( :adapter ) { Yell::Adapters::Stdout.new :format => "%F, %n: %M" }
|
111
134
|
let( :logger ) { Yell::Logger.new { |l| l.adapter adapter } }
|
data/spec/yell_spec.rb
CHANGED
@@ -5,8 +5,8 @@ describe Yell do
|
|
5
5
|
|
6
6
|
it { should be_kind_of Yell::Logger }
|
7
7
|
|
8
|
-
it "should raise
|
9
|
-
lambda { Yell.new :unknownadapter }.should raise_error( Yell::
|
8
|
+
it "should raise UnregisteredAdapter when adapter cant be loaded" do
|
9
|
+
lambda { Yell.new :unknownadapter }.should raise_error( Yell::UnregisteredAdapter )
|
10
10
|
end
|
11
11
|
|
12
12
|
context :level do
|
@@ -21,4 +21,17 @@ describe Yell do
|
|
21
21
|
it { should be_kind_of Yell::Formatter }
|
22
22
|
end
|
23
23
|
|
24
|
+
context :load! do
|
25
|
+
subject { Yell.load!( File.dirname(__FILE__) + '/fixtures/yell.yml' ) }
|
26
|
+
|
27
|
+
let( :adapters ) { subject.instance_variable_get :@adapters }
|
28
|
+
|
29
|
+
it { should be_kind_of Yell::Logger }
|
30
|
+
|
31
|
+
it "should return a Yell instacne with the configuration for a file" do
|
32
|
+
adapters.first.should be_kind_of Yell::Adapters::Stdout
|
33
|
+
adapters.last.should be_kind_of Yell::Adapters::Stderr
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
24
37
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 9
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.9.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Rudolf Schmidt
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-
|
17
|
+
date: 2012-05-11 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -84,11 +84,13 @@ files:
|
|
84
84
|
- lib/yell/adapters/file.rb
|
85
85
|
- lib/yell/adapters/io.rb
|
86
86
|
- lib/yell/adapters/streams.rb
|
87
|
+
- lib/yell/configuration.rb
|
87
88
|
- lib/yell/event.rb
|
88
89
|
- lib/yell/formatter.rb
|
89
90
|
- lib/yell/level.rb
|
90
91
|
- lib/yell/logger.rb
|
91
92
|
- lib/yell/version.rb
|
93
|
+
- spec/fixtures/yell.yml
|
92
94
|
- spec/spec_helper.rb
|
93
95
|
- spec/yell/adapters/base_spec.rb
|
94
96
|
- spec/yell/adapters/datefile_spec.rb
|
@@ -96,6 +98,7 @@ files:
|
|
96
98
|
- spec/yell/adapters/io_spec.rb
|
97
99
|
- spec/yell/adapters/streams_spec.rb
|
98
100
|
- spec/yell/adapters_spec.rb
|
101
|
+
- spec/yell/configuration_spec.rb
|
99
102
|
- spec/yell/event_spec.rb
|
100
103
|
- spec/yell/formatter_spec.rb
|
101
104
|
- spec/yell/level_spec.rb
|
@@ -133,6 +136,7 @@ signing_key:
|
|
133
136
|
specification_version: 3
|
134
137
|
summary: Yell - Your Extensible Logging Library
|
135
138
|
test_files:
|
139
|
+
- spec/fixtures/yell.yml
|
136
140
|
- spec/spec_helper.rb
|
137
141
|
- spec/yell/adapters/base_spec.rb
|
138
142
|
- spec/yell/adapters/datefile_spec.rb
|
@@ -140,6 +144,7 @@ test_files:
|
|
140
144
|
- spec/yell/adapters/io_spec.rb
|
141
145
|
- spec/yell/adapters/streams_spec.rb
|
142
146
|
- spec/yell/adapters_spec.rb
|
147
|
+
- spec/yell/configuration_spec.rb
|
143
148
|
- spec/yell/event_spec.rb
|
144
149
|
- spec/yell/formatter_spec.rb
|
145
150
|
- spec/yell/level_spec.rb
|