yell 0.12.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/yell.rb +32 -12
- data/lib/yell/logger.rb +1 -1
- data/lib/yell/repository.rb +44 -0
- data/lib/yell/version.rb +1 -1
- data/spec/spec_helper.rb +4 -0
- data/spec/threaded/yell_spec.rb +41 -0
- data/spec/yell/event_spec.rb +2 -2
- data/spec/yell/repository_spec.rb +33 -0
- metadata +85 -74
data/lib/yell.rb
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
#
|
13
13
|
# The above copyright notice and this permission notice shall be
|
14
14
|
# included in all copies or substantial portions of the Software.
|
15
|
-
|
15
|
+
|
16
16
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
17
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
18
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -22,6 +22,8 @@
|
|
22
22
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
23
|
|
24
24
|
module Yell #:nodoc:
|
25
|
+
|
26
|
+
# Holds all Yell severities
|
25
27
|
Severities = [ 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL', 'UNKNOWN' ]
|
26
28
|
|
27
29
|
class << self
|
@@ -36,11 +38,25 @@ module Yell #:nodoc:
|
|
36
38
|
|
37
39
|
# Shortcut to Yell::Level.new
|
38
40
|
#
|
39
|
-
# @return [Yell::Level]
|
41
|
+
# @return [Yell::Level] The level instance
|
40
42
|
def level( val = nil )
|
41
43
|
Yell::Level.new( val )
|
42
44
|
end
|
43
45
|
|
46
|
+
# Shortcut to Yell::Repository[]
|
47
|
+
#
|
48
|
+
# @return [Yell::Logger] The logger instance
|
49
|
+
def []( name )
|
50
|
+
Yell::Repository[ name ]
|
51
|
+
end
|
52
|
+
|
53
|
+
# Shortcut to Yell::Repository[]=
|
54
|
+
#
|
55
|
+
# @return [Yell::Logger] The logger instance
|
56
|
+
def []=( name, logger )
|
57
|
+
Yell::Repository[ name ] = logger
|
58
|
+
end
|
59
|
+
|
44
60
|
# Shortcut to Yell::Fomatter.new
|
45
61
|
#
|
46
62
|
# @return [Yell::Formatter] A Yell::Formatter instance
|
@@ -48,28 +64,32 @@ module Yell #:nodoc:
|
|
48
64
|
Yell::Formatter.new( pattern, date_pattern )
|
49
65
|
end
|
50
66
|
|
51
|
-
|
52
|
-
ENV['YELL_ENV'] || ENV['RACK_ENV'] ||ENV['RAILS_ENV'] || 'development'
|
53
|
-
end
|
54
|
-
|
67
|
+
# Loads a config from a YAML file
|
55
68
|
def load!( file )
|
56
69
|
Yell.new Yell::Configuration.load!( file )
|
57
70
|
end
|
58
71
|
|
59
|
-
def
|
60
|
-
|
61
|
-
|
62
|
-
|
72
|
+
def env #:nodoc:
|
73
|
+
ENV['YELL_ENV'] || ENV['RACK_ENV'] ||ENV['RAILS_ENV'] || 'development'
|
74
|
+
end
|
75
|
+
|
76
|
+
def _deprecate( version, message, options = {} ) #:nodoc:
|
77
|
+
messages = ["Deprecation Warning (since v#{version}): #{message}" ]
|
78
|
+
messages << " before: #{options[:before]}" if options[:before]
|
79
|
+
messages << " after: #{options[:after]}" if options[:after]
|
63
80
|
|
64
|
-
|
81
|
+
_warn( *messages )
|
65
82
|
end
|
66
83
|
|
84
|
+
def _warn( *messages )
|
85
|
+
$stderr.puts messages.join( "\n" )
|
86
|
+
end
|
67
87
|
end
|
68
88
|
|
69
89
|
end
|
70
90
|
|
71
91
|
require File.dirname(__FILE__) + '/yell/configuration'
|
72
|
-
|
92
|
+
require File.dirname(__FILE__) + '/yell/repository'
|
73
93
|
require File.dirname(__FILE__) + '/yell/event'
|
74
94
|
require File.dirname(__FILE__) + '/yell/level'
|
75
95
|
require File.dirname(__FILE__) + '/yell/formatter'
|
data/lib/yell/logger.rb
CHANGED
@@ -77,7 +77,7 @@ module Yell #:nodoc:
|
|
77
77
|
#
|
78
78
|
# @param [Symbol] type The type of the adapter, may be `:file` or `:datefile` (default `:file`)
|
79
79
|
#
|
80
|
-
# @return
|
80
|
+
# @return [Yell::Adapter] The instance
|
81
81
|
#
|
82
82
|
# @raise [Yell::NoSuchAdapter] Will be thrown when the adapter is not defined
|
83
83
|
def adapter( type = :file, *args, &block )
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'monitor'
|
4
|
+
require "singleton"
|
5
|
+
|
6
|
+
module Yell #:nodoc:
|
7
|
+
class Repository
|
8
|
+
extend MonitorMixin
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
attr_accessor :loggers
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@loggers = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
# Set loggers in the repository
|
18
|
+
#
|
19
|
+
# @example Set a logger
|
20
|
+
# Yell::Repository[ 'development' ] = Yell::Logger.new :stdout
|
21
|
+
#
|
22
|
+
# @return [Yell::Logger] The logger instance
|
23
|
+
def self.[]=( name, logger )
|
24
|
+
synchronize { instance.loggers[name] = logger }
|
25
|
+
end
|
26
|
+
|
27
|
+
# Get loggers from the repository
|
28
|
+
#
|
29
|
+
# @example Get the logger
|
30
|
+
# Yell::Repository[ 'development' ]
|
31
|
+
#
|
32
|
+
# @return [Yell::Logger] The logger instance
|
33
|
+
def self.[]( name )
|
34
|
+
synchronize { instance.loggers[name] }
|
35
|
+
end
|
36
|
+
|
37
|
+
# Clears all logger instances (handy for testing)
|
38
|
+
def self.clear
|
39
|
+
synchronize { instance.loggers.clear }
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
data/lib/yell/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "running Yell multi-threaded" do
|
4
|
+
let( :threads ) { 100 }
|
5
|
+
|
6
|
+
let( :filename ) { fixture_path + '/threaded.log' }
|
7
|
+
let( :lines ) { `wc -l #{filename}`.to_i }
|
8
|
+
|
9
|
+
it "should write all messages from one instance" do
|
10
|
+
logger = Yell.new( filename )
|
11
|
+
|
12
|
+
(1..threads).map do |count|
|
13
|
+
Thread.new { 10.times { logger.info count } }
|
14
|
+
end.each(&:join)
|
15
|
+
|
16
|
+
lines.should == 10*threads
|
17
|
+
end
|
18
|
+
|
19
|
+
# it "should write all messages from multiple instances" do
|
20
|
+
# (1..threads).map do |count|
|
21
|
+
# logger = Yell.new( filename )
|
22
|
+
|
23
|
+
# Thread.new do
|
24
|
+
# 10.times { logger.info count }
|
25
|
+
# end
|
26
|
+
# end.each(&:join)
|
27
|
+
|
28
|
+
# lines.should == 10*threads
|
29
|
+
# end
|
30
|
+
|
31
|
+
it "should write all messages from one repository" do
|
32
|
+
Yell[ 'threaded' ] = Yell.new( filename )
|
33
|
+
|
34
|
+
(1..threads).map do |count|
|
35
|
+
Thread.new { 10.times { Yell['threaded'].info count } }
|
36
|
+
end.each(&:join)
|
37
|
+
|
38
|
+
lines.should == 10*threads
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/spec/yell/event_spec.rb
CHANGED
@@ -54,7 +54,7 @@ describe Yell::Event do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
context :time do
|
57
|
-
subject { event.time }
|
57
|
+
subject { event.time.to_s }
|
58
58
|
|
59
59
|
let(:time) { Time.now }
|
60
60
|
|
@@ -62,7 +62,7 @@ describe Yell::Event do
|
|
62
62
|
Timecop.freeze( time )
|
63
63
|
end
|
64
64
|
|
65
|
-
it { should == time }
|
65
|
+
it { should == time.to_s }
|
66
66
|
end
|
67
67
|
|
68
68
|
context :hostname do
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yell::Repository do
|
4
|
+
let( :name ) { 'test' }
|
5
|
+
let( :logger ) { Yell.new :stdout }
|
6
|
+
|
7
|
+
subject { Yell[name] }
|
8
|
+
|
9
|
+
|
10
|
+
context ".[]" do
|
11
|
+
context "when not set" do
|
12
|
+
it { should be_nil }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when assigned" do
|
16
|
+
before do
|
17
|
+
Yell[ name ] = logger
|
18
|
+
end
|
19
|
+
|
20
|
+
it { should == logger }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context ".[]=" do
|
25
|
+
before do
|
26
|
+
Yell[ name ] = logger
|
27
|
+
end
|
28
|
+
|
29
|
+
it { should == logger }
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
metadata
CHANGED
@@ -1,97 +1,108 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: yell
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.13.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.12.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
|
7
|
+
authors:
|
8
|
+
- Rudolf Schmidt
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2012-08-29 00:00:00 Z
|
12
|
+
date: 2012-09-04 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
|
-
|
16
|
-
|
14
|
+
description: Yell - Your Extensible Logging Library. Define multiple adapters, various
|
15
|
+
log level combinations or message formatting options like you've never done before
|
17
16
|
email:
|
18
17
|
executables: []
|
19
|
-
|
20
18
|
extensions: []
|
21
|
-
|
22
19
|
extra_rdoc_files: []
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .travis.yml
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- examples/001-basic-usage.rb
|
28
|
+
- examples/002.1-log-level-basics.rb
|
29
|
+
- examples/002.2-log-level-on-certain-severities-only.rb
|
30
|
+
- examples/002.3-log-level-within-range.rb
|
31
|
+
- examples/003.1-formatting-DefaultFormat.rb
|
32
|
+
- examples/003.2-formatting-BasicFormat.rb
|
33
|
+
- examples/003.3-formatting-ExtendedFormat.rb
|
34
|
+
- examples/003.4-formatting-on-your-own.rb
|
35
|
+
- examples/004.1-colorizing-the-log-output.rb
|
36
|
+
- lib/yell.rb
|
37
|
+
- lib/yell/adapters.rb
|
38
|
+
- lib/yell/adapters/base.rb
|
39
|
+
- lib/yell/adapters/datefile.rb
|
40
|
+
- lib/yell/adapters/file.rb
|
41
|
+
- lib/yell/adapters/io.rb
|
42
|
+
- lib/yell/adapters/streams.rb
|
43
|
+
- lib/yell/configuration.rb
|
44
|
+
- lib/yell/event.rb
|
45
|
+
- lib/yell/formatter.rb
|
46
|
+
- lib/yell/level.rb
|
47
|
+
- lib/yell/logger.rb
|
48
|
+
- lib/yell/repository.rb
|
49
|
+
- lib/yell/version.rb
|
50
|
+
- spec/fixtures/yell.yml
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
- spec/threaded/yell_spec.rb
|
53
|
+
- spec/yell/adapters/base_spec.rb
|
54
|
+
- spec/yell/adapters/datefile_spec.rb
|
55
|
+
- spec/yell/adapters/file_spec.rb
|
56
|
+
- spec/yell/adapters/io_spec.rb
|
57
|
+
- spec/yell/adapters/streams_spec.rb
|
58
|
+
- spec/yell/adapters_spec.rb
|
59
|
+
- spec/yell/configuration_spec.rb
|
60
|
+
- spec/yell/event_spec.rb
|
61
|
+
- spec/yell/formatter_spec.rb
|
62
|
+
- spec/yell/level_spec.rb
|
63
|
+
- spec/yell/logger_spec.rb
|
64
|
+
- spec/yell/repository_spec.rb
|
65
|
+
- spec/yell_spec.rb
|
66
|
+
- yell.gemspec
|
68
67
|
homepage: http://rudionrails.github.com/yell
|
69
68
|
licenses: []
|
70
|
-
|
71
69
|
post_install_message:
|
72
70
|
rdoc_options: []
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
74
|
none: false
|
78
|
-
requirements:
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
80
|
none: false
|
84
|
-
requirements:
|
85
|
-
|
86
|
-
|
87
|
-
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
88
85
|
requirements: []
|
89
|
-
|
90
86
|
rubyforge_project: yell
|
91
|
-
rubygems_version: 1.8.
|
87
|
+
rubygems_version: 1.8.23
|
92
88
|
signing_key:
|
93
89
|
specification_version: 3
|
94
90
|
summary: Yell - Your Extensible Logging Library
|
95
|
-
test_files:
|
96
|
-
|
91
|
+
test_files:
|
92
|
+
- spec/fixtures/yell.yml
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
- spec/threaded/yell_spec.rb
|
95
|
+
- spec/yell/adapters/base_spec.rb
|
96
|
+
- spec/yell/adapters/datefile_spec.rb
|
97
|
+
- spec/yell/adapters/file_spec.rb
|
98
|
+
- spec/yell/adapters/io_spec.rb
|
99
|
+
- spec/yell/adapters/streams_spec.rb
|
100
|
+
- spec/yell/adapters_spec.rb
|
101
|
+
- spec/yell/configuration_spec.rb
|
102
|
+
- spec/yell/event_spec.rb
|
103
|
+
- spec/yell/formatter_spec.rb
|
104
|
+
- spec/yell/level_spec.rb
|
105
|
+
- spec/yell/logger_spec.rb
|
106
|
+
- spec/yell/repository_spec.rb
|
107
|
+
- spec/yell_spec.rb
|
97
108
|
has_rdoc:
|