yell 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/lib/yell/adapters.rb +29 -32
- data/lib/yell/adapters/base.rb +11 -4
- data/lib/yell/adapters/datefile.rb +3 -1
- data/lib/yell/adapters/file.rb +3 -1
- data/lib/yell/adapters/io.rb +18 -16
- data/lib/yell/adapters/streams.rb +27 -0
- data/lib/yell/event.rb +1 -1
- data/lib/yell/level.rb +3 -3
- data/lib/yell/logger.rb +0 -2
- data/lib/yell/version.rb +1 -1
- data/spec/yell/level_spec.rb +93 -0
- metadata +60 -70
- data/lib/yell/adapters/.file.rb.swp +0 -0
data/.gitignore
CHANGED
data/lib/yell/adapters.rb
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'yell/adapters/base'
|
4
|
-
require 'yell/adapters/io'
|
5
|
-
require 'yell/adapters/file'
|
6
|
-
require 'yell/adapters/datefile'
|
7
|
-
|
8
3
|
module Yell #:nodoc:
|
9
4
|
|
10
5
|
# NoSuchAdapter is raised whenever you want to instantiate an
|
@@ -15,44 +10,46 @@ module Yell #:nodoc:
|
|
15
10
|
# the logger. You should not have to call the corresponding classes
|
16
11
|
# directly.
|
17
12
|
module Adapters
|
13
|
+
@@adapters = {}
|
18
14
|
|
19
15
|
class << self
|
16
|
+
|
17
|
+
# Register your own adapter here
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# Yell::Adapters.register( :myadapter, MyAdapter )
|
21
|
+
def register( name, klass )
|
22
|
+
@@adapters[name] = klass
|
23
|
+
end
|
24
|
+
|
20
25
|
# Returns an instance of the given processor type.
|
21
26
|
#
|
22
27
|
# @example A simple file adapter
|
23
28
|
# Yell::Adapters.new( :file )
|
24
|
-
def new(
|
25
|
-
|
26
|
-
|
27
|
-
if type.instance_of?( ::IO )
|
28
|
-
# should apply to STDOUT, STDERR, File, etc
|
29
|
-
Yell::Adapters::Io.new( type, options, &block )
|
30
|
-
else
|
31
|
-
# any other type
|
32
|
-
adapter = case type
|
33
|
-
when String, Symbol then self.const_get( camelize(type.to_s) )
|
34
|
-
else type
|
35
|
-
end
|
36
|
-
|
37
|
-
adapter.new( options, &block )
|
38
|
-
end
|
39
|
-
end
|
29
|
+
def new( name, options = {}, &block )
|
30
|
+
return name if name.is_a?( Yell::Adapters::Base )
|
40
31
|
|
32
|
+
adapter = case name
|
33
|
+
when STDOUT then @@adapters[:stdout]
|
34
|
+
when STDERR then @@adapters[:stderr]
|
35
|
+
else @@adapters[name]
|
36
|
+
end
|
41
37
|
|
42
|
-
|
38
|
+
raise NoSuchAdapter.new( name ) unless adapter
|
43
39
|
|
44
|
-
|
45
|
-
#
|
46
|
-
# @example
|
47
|
-
# camelize("file")
|
48
|
-
# #=> "File"
|
49
|
-
#
|
50
|
-
# camelize("date_file")
|
51
|
-
# #=> "DateFile"
|
52
|
-
def camelize( str )
|
53
|
-
str.capitalize.gsub( /(_\w)/ ) { |match| match.reverse.chop.upcase }
|
40
|
+
adapter.new( options, &block )
|
54
41
|
end
|
42
|
+
|
55
43
|
end
|
56
44
|
|
57
45
|
end
|
58
46
|
end
|
47
|
+
|
48
|
+
require 'yell/adapters/base'
|
49
|
+
|
50
|
+
# IO based adapters
|
51
|
+
require 'yell/adapters/io'
|
52
|
+
require 'yell/adapters/streams'
|
53
|
+
require 'yell/adapters/file'
|
54
|
+
require 'yell/adapters/datefile'
|
55
|
+
|
data/lib/yell/adapters/base.rb
CHANGED
@@ -6,9 +6,15 @@ module Yell #:nodoc:
|
|
6
6
|
# This class provides the basic interface for all allowed
|
7
7
|
# operations on any adapter implementation.
|
8
8
|
#
|
9
|
-
# Other adapters should
|
9
|
+
# Other adapters should inherit from it for the methods used
|
10
10
|
# by the {Yell::Logger}.
|
11
|
-
|
11
|
+
class Base
|
12
|
+
|
13
|
+
def initialize( options = {}, &block )
|
14
|
+
level options[:level]
|
15
|
+
|
16
|
+
instance_eval( &block ) if block
|
17
|
+
end
|
12
18
|
|
13
19
|
# The main method for calling the adapter.
|
14
20
|
#
|
@@ -36,6 +42,7 @@ module Yell #:nodoc:
|
|
36
42
|
@level = Yell::Level.new( severity )
|
37
43
|
end
|
38
44
|
|
45
|
+
|
39
46
|
private
|
40
47
|
|
41
48
|
# The perform the actual write.
|
@@ -49,9 +56,9 @@ module Yell #:nodoc:
|
|
49
56
|
# Determine whether to write at the given severity.
|
50
57
|
#
|
51
58
|
# @example
|
52
|
-
# write?
|
59
|
+
# write? Yell::Event.new( 'INFO', 'Hwllo Wold!' )
|
53
60
|
#
|
54
|
-
# @param [
|
61
|
+
# @param [Yell::Event] event The log event
|
55
62
|
#
|
56
63
|
# @return [Boolean] true or false
|
57
64
|
def write?( event )
|
@@ -18,7 +18,7 @@ module Yell #:nodoc:
|
|
18
18
|
|
19
19
|
@date = nil # default; do not override --R
|
20
20
|
|
21
|
-
super
|
21
|
+
super
|
22
22
|
end
|
23
23
|
|
24
24
|
# @overload Reset the file handle
|
@@ -61,5 +61,7 @@ module Yell #:nodoc:
|
|
61
61
|
|
62
62
|
end
|
63
63
|
|
64
|
+
register( :datefile, Yell::Adapters::Datefile )
|
65
|
+
|
64
66
|
end
|
65
67
|
end
|
data/lib/yell/adapters/file.rb
CHANGED
@@ -8,7 +8,7 @@ module Yell #:nodoc:
|
|
8
8
|
class File < Yell::Adapters::Io
|
9
9
|
|
10
10
|
def initialize( options = {}, &block )
|
11
|
-
super
|
11
|
+
super
|
12
12
|
|
13
13
|
@filename = options.fetch(:filename, default_filename)
|
14
14
|
end
|
@@ -27,6 +27,8 @@ module Yell #:nodoc:
|
|
27
27
|
|
28
28
|
end
|
29
29
|
|
30
|
+
register( :file, Yell::Adapters::File )
|
31
|
+
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
data/lib/yell/adapters/io.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module Yell
|
2
2
|
module Adapters
|
3
3
|
|
4
|
-
class Io
|
5
|
-
include Yell::Adapters::Base
|
4
|
+
class Io < Yell::Adapters::Base
|
6
5
|
|
7
6
|
# The possible unix log colors
|
8
7
|
Colors = {
|
@@ -15,19 +14,27 @@ module Yell
|
|
15
14
|
'DEFAULT' => "\e[0m" # NONE
|
16
15
|
}
|
17
16
|
|
18
|
-
# Accessor to the io stream
|
19
|
-
attr_reader :stream
|
20
17
|
|
18
|
+
def initialize( options = {}, &block )
|
19
|
+
format options[:format]
|
20
|
+
colorize options.fetch(:colorize, false)
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
@options = options
|
22
|
+
super
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
# The IO stream
|
26
|
+
#
|
27
|
+
# Adapter classes should provide their own implementation
|
28
|
+
# of this method.
|
29
|
+
def stream
|
30
|
+
raise 'Not implemented'
|
31
|
+
end
|
32
|
+
|
33
|
+
# Close the io stream
|
34
|
+
def close
|
35
|
+
@stream.close if @stream.respond_to? :close
|
29
36
|
|
30
|
-
|
37
|
+
@stream = nil
|
31
38
|
end
|
32
39
|
|
33
40
|
# Set the format for your message.
|
@@ -44,11 +51,6 @@ module Yell
|
|
44
51
|
@colorize = color
|
45
52
|
end
|
46
53
|
|
47
|
-
def close
|
48
|
-
@stream.close if @stream.respond_to? :close
|
49
|
-
|
50
|
-
@stream = nil
|
51
|
-
end
|
52
54
|
|
53
55
|
private
|
54
56
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Yell #:nodoc:
|
4
|
+
module Adapters #:nodoc:
|
5
|
+
|
6
|
+
class Stdout < Yell::Adapters::Io
|
7
|
+
|
8
|
+
# @overload Lazily open the STDOUT stream
|
9
|
+
def stream
|
10
|
+
@stream ||= $stdout.clone
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Stderr < Yell::Adapters::Io
|
15
|
+
|
16
|
+
# @overload Lazily open the STDERR stream
|
17
|
+
def stream
|
18
|
+
@stream ||= $stderr.clone
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
register( :stdout, Yell::Adapters::Stdout )
|
23
|
+
register( :stderr, Yell::Adapters::Stderr )
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
data/lib/yell/event.rb
CHANGED
data/lib/yell/level.rb
CHANGED
@@ -47,7 +47,7 @@ module Yell #:nodoc:
|
|
47
47
|
@severities = Yell::Severities.map { true } # all levels allowed by default
|
48
48
|
|
49
49
|
case severity
|
50
|
-
when Array then severity
|
50
|
+
when Array then at( *severity )
|
51
51
|
when Range then gte(severity.first).lte(severity.last)
|
52
52
|
when Integer, String, Symbol then gte(severity)
|
53
53
|
end
|
@@ -64,8 +64,8 @@ module Yell #:nodoc:
|
|
64
64
|
index.nil? ? false : @severities[index]
|
65
65
|
end
|
66
66
|
|
67
|
-
def at(
|
68
|
-
calculate! :==, severity
|
67
|
+
def at( *severities ) #:nodoc:
|
68
|
+
severities.each { |severity| calculate! :==, severity }
|
69
69
|
self
|
70
70
|
end
|
71
71
|
|
data/lib/yell/logger.rb
CHANGED
data/lib/yell/version.rb
CHANGED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yell::Level do
|
4
|
+
|
5
|
+
context "default" do
|
6
|
+
let( :level ) { Yell::Level.new }
|
7
|
+
|
8
|
+
it { level.at?(:debug).should be_true }
|
9
|
+
it { level.at?(:info).should be_true }
|
10
|
+
it { level.at?(:warn).should be_true }
|
11
|
+
it { level.at?(:error).should be_true }
|
12
|
+
it { level.at?(:fatal).should be_true }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "given a Symbol" do
|
16
|
+
let( :level ) { Yell::Level.new(subject) }
|
17
|
+
|
18
|
+
context :debug do
|
19
|
+
subject { :debug }
|
20
|
+
|
21
|
+
it { level.at?(:debug).should be_true }
|
22
|
+
it { level.at?(:info).should be_true }
|
23
|
+
it { level.at?(:warn).should be_true }
|
24
|
+
it { level.at?(:error).should be_true }
|
25
|
+
it { level.at?(:fatal).should be_true }
|
26
|
+
end
|
27
|
+
|
28
|
+
context :info do
|
29
|
+
subject { :info }
|
30
|
+
|
31
|
+
it { level.at?(:debug).should be_false }
|
32
|
+
it { level.at?(:info).should be_true }
|
33
|
+
it { level.at?(:warn).should be_true }
|
34
|
+
it { level.at?(:error).should be_true }
|
35
|
+
it { level.at?(:fatal).should be_true }
|
36
|
+
end
|
37
|
+
|
38
|
+
context :warn do
|
39
|
+
subject { :warn }
|
40
|
+
|
41
|
+
it { level.at?(:debug).should be_false }
|
42
|
+
it { level.at?(:info).should be_false }
|
43
|
+
it { level.at?(:warn).should be_true }
|
44
|
+
it { level.at?(:error).should be_true }
|
45
|
+
it { level.at?(:fatal).should be_true }
|
46
|
+
end
|
47
|
+
|
48
|
+
context :error do
|
49
|
+
subject { :error }
|
50
|
+
|
51
|
+
it { level.at?(:debug).should be_false }
|
52
|
+
it { level.at?(:info).should be_false }
|
53
|
+
it { level.at?(:warn).should be_false }
|
54
|
+
it { level.at?(:error).should be_true }
|
55
|
+
it { level.at?(:fatal).should be_true }
|
56
|
+
end
|
57
|
+
|
58
|
+
context :fatal do
|
59
|
+
subject { :fatal }
|
60
|
+
|
61
|
+
it { level.at?(:debug).should be_false }
|
62
|
+
it { level.at?(:info).should be_false }
|
63
|
+
it { level.at?(:warn).should be_false }
|
64
|
+
it { level.at?(:error).should be_false }
|
65
|
+
it { level.at?(:fatal).should be_true }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "given an Array" do
|
70
|
+
let( :level ) { Yell::Level.new(subject) }
|
71
|
+
|
72
|
+
subject { [:debug, :warn, :fatal] }
|
73
|
+
|
74
|
+
it { level.at?(:debug).should be_true }
|
75
|
+
it { level.at?(:info).should be_false }
|
76
|
+
it { level.at?(:warn).should be_true }
|
77
|
+
it { level.at?(:error).should be_false }
|
78
|
+
it { level.at?(:fatal).should be_true }
|
79
|
+
end
|
80
|
+
|
81
|
+
context "given a Range" do
|
82
|
+
let( :level ) { Yell::Level.new(subject) }
|
83
|
+
|
84
|
+
subject { (1..3) }
|
85
|
+
|
86
|
+
it { level.at?(:debug).should be_false }
|
87
|
+
it { level.at?(:info).should be_true }
|
88
|
+
it { level.at?(:warn).should be_true }
|
89
|
+
it { level.at?(:error).should be_true }
|
90
|
+
it { level.at?(:fatal).should be_false }
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
metadata
CHANGED
@@ -1,34 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 3
|
8
|
-
- 3
|
9
|
-
version: 0.3.3
|
4
|
+
prerelease:
|
5
|
+
version: 0.4.0
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
|
-
- Rudolf Schmidt
|
8
|
+
- Rudolf Schmidt
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2012-03-
|
18
|
-
default_executable:
|
13
|
+
date: 2012-03-27 00:00:00 Z
|
19
14
|
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
version_requirements: *id001
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rr
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :development
|
25
|
+
version_requirements: *id001
|
32
26
|
description: An easy to use logging library to log into files and any other self-defined adapters
|
33
27
|
email:
|
34
28
|
executables: []
|
@@ -38,38 +32,38 @@ extensions: []
|
|
38
32
|
extra_rdoc_files: []
|
39
33
|
|
40
34
|
files:
|
41
|
-
- .gitignore
|
42
|
-
- .travis.yml
|
43
|
-
- Gemfile
|
44
|
-
- LICENSE.txt
|
45
|
-
- README.md
|
46
|
-
- Rakefile
|
47
|
-
- examples/001-basic-usage.rb
|
48
|
-
- examples/002.1-log-level-basics.rb
|
49
|
-
- examples/002.2-log-level-on-certain-severities-only.rb
|
50
|
-
- examples/002.3-log-level-within-range.rb
|
51
|
-
- examples/003.1-formatting-DefaultFormat.rb
|
52
|
-
- examples/003.2-formatting-BasicFormat.rb
|
53
|
-
- examples/003.3-formatting-ExtendedFormat.rb
|
54
|
-
- examples/003.4-formatting-on-your-own.rb
|
55
|
-
- lib/yell.rb
|
56
|
-
- lib/yell/adapters.rb
|
57
|
-
- lib/yell/adapters
|
58
|
-
- lib/yell/adapters/
|
59
|
-
- lib/yell/adapters/
|
60
|
-
- lib/yell/adapters/
|
61
|
-
- lib/yell/adapters/
|
62
|
-
- lib/yell/event.rb
|
63
|
-
- lib/yell/formatter.rb
|
64
|
-
- lib/yell/level.rb
|
65
|
-
- lib/yell/logger.rb
|
66
|
-
- lib/yell/version.rb
|
67
|
-
- spec/spec_helper.rb
|
68
|
-
- spec/yell/event_spec.rb
|
69
|
-
- spec/yell/formatter_spec.rb
|
70
|
-
- spec/
|
71
|
-
-
|
72
|
-
|
35
|
+
- .gitignore
|
36
|
+
- .travis.yml
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- examples/001-basic-usage.rb
|
42
|
+
- examples/002.1-log-level-basics.rb
|
43
|
+
- examples/002.2-log-level-on-certain-severities-only.rb
|
44
|
+
- examples/002.3-log-level-within-range.rb
|
45
|
+
- examples/003.1-formatting-DefaultFormat.rb
|
46
|
+
- examples/003.2-formatting-BasicFormat.rb
|
47
|
+
- examples/003.3-formatting-ExtendedFormat.rb
|
48
|
+
- examples/003.4-formatting-on-your-own.rb
|
49
|
+
- lib/yell.rb
|
50
|
+
- lib/yell/adapters.rb
|
51
|
+
- lib/yell/adapters/base.rb
|
52
|
+
- lib/yell/adapters/datefile.rb
|
53
|
+
- lib/yell/adapters/file.rb
|
54
|
+
- lib/yell/adapters/io.rb
|
55
|
+
- lib/yell/adapters/streams.rb
|
56
|
+
- lib/yell/event.rb
|
57
|
+
- lib/yell/formatter.rb
|
58
|
+
- lib/yell/level.rb
|
59
|
+
- lib/yell/logger.rb
|
60
|
+
- lib/yell/version.rb
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
- spec/yell/event_spec.rb
|
63
|
+
- spec/yell/formatter_spec.rb
|
64
|
+
- spec/yell/level_spec.rb
|
65
|
+
- spec/yell_spec.rb
|
66
|
+
- yell.gemspec
|
73
67
|
homepage: http://rubygems.org/gems/yell
|
74
68
|
licenses: []
|
75
69
|
|
@@ -77,30 +71,26 @@ post_install_message:
|
|
77
71
|
rdoc_options: []
|
78
72
|
|
79
73
|
require_paths:
|
80
|
-
- lib
|
74
|
+
- lib
|
81
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
82
77
|
requirements:
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
- 0
|
87
|
-
version: "0"
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: "0"
|
88
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
89
83
|
requirements:
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
- 0
|
94
|
-
version: "0"
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: "0"
|
95
87
|
requirements: []
|
96
88
|
|
97
89
|
rubyforge_project: yell
|
98
|
-
rubygems_version: 1.
|
90
|
+
rubygems_version: 1.8.9
|
99
91
|
signing_key:
|
100
92
|
specification_version: 3
|
101
93
|
summary: Yell - Your Extensible Logging Library
|
102
|
-
test_files:
|
103
|
-
|
104
|
-
|
105
|
-
- spec/yell/formatter_spec.rb
|
106
|
-
- spec/yell_spec.rb
|
94
|
+
test_files: []
|
95
|
+
|
96
|
+
has_rdoc:
|
Binary file
|