yell 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+
3
+ script: "rake"
4
+
5
+ rvm:
6
+ - 1.9.3
7
+
8
+ notifications:
9
+ email:
10
+ - me@rudionrails.com
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  Yell - Your Extensible Logging Library
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/rudionrails/yell.png)](http://travis-ci.org/rudionrails/yell)
4
+
3
5
  ## Installation
4
6
 
5
7
  System wide:
@@ -11,10 +13,11 @@ gem install yell
11
13
  Or in your Gemfile:
12
14
 
13
15
  ```ruby
14
- gem 'yell'
16
+ gem "yell"
15
17
  ```
16
18
 
17
19
  ## Usage
20
+
18
21
  On the basics, Yell works just like any other logging library. However, it
19
22
  tries to make your log mesages more readable. By default, it will format the given
20
23
  message as follows:
@@ -32,17 +35,20 @@ When no arguments are given, Yell will check for `ENV['RACK_ENV']` and
32
35
  determine the filename from that.
33
36
 
34
37
  Alternatively, you may define `ENV['YELL_ENV']` to set the filename. If neither
35
- `YELL_ENV` or `RACK_ENV` is defined, `'development'` will be the default. Also, if a
38
+ `YELL_ENV` or `RACK_ENV` is defined, *'development'* will be the default. Also, if a
36
39
  `log` directory exists, Yell will place the file there (only if you have not passed
37
40
  a filename explicitly.
38
41
 
39
42
  Naturally, you can pass a `:filename` to Yell:
40
43
 
41
44
  ```ruby
42
- logger = Yell.new 'yell.log'
45
+ logger = Yell.new "yell.log"
43
46
  ```
44
47
 
45
- To learn about how to use [log levels](https://github.com/rudionrails/yell/wiki/101-setting-the-log-level), [log formatting](https://github.com/rudionrails/yell/wiki/101-formatting-log-messages), or different [adapters](https://github.com/rudionrails/yell/wiki/101-using-adapters) see the [wiki](https://github.com/rudionrails/yell/wiki) or have a look into the examples folder.
48
+ To learn about how to use [log levels](https://github.com/rudionrails/yell/wiki/101-setting-the-log-level),
49
+ [log formatting](https://github.com/rudionrails/yell/wiki/101-formatting-log-messages), or different
50
+ [adapters](https://github.com/rudionrails/yell/wiki/101-using-adapters) see the
51
+ [wiki](https://github.com/rudionrails/yell/wiki) or have a look into the examples folder.
46
52
 
47
53
 
48
54
  Copyright © 2011-2012 Rudolf Schmidt, released under the MIT license
data/Rakefile CHANGED
@@ -4,23 +4,19 @@ require 'bundler'
4
4
  Bundler::GemHelper.install_tasks
5
5
 
6
6
  # === RSpec
7
- require 'rspec/core/rake_task'
7
+ begin
8
+ require 'rspec/core/rake_task'
8
9
 
9
- desc "Run specs"
10
- RSpec::Core::RakeTask.new do |t|
11
- t.rspec_opts = %w(-fs --color)
10
+ desc "Run specs"
11
+ RSpec::Core::RakeTask.new do |t|
12
+ t.rspec_opts = %w(--color --format progress --order random)
13
+ t.ruby_opts = %w(-w)
14
+ end
15
+ rescue LoadError
16
+ task :spec do
17
+ abort "`gem install rspec` in order to run tests"
18
+ end
12
19
  end
13
20
 
14
21
  task :default => :spec
15
22
 
16
-
17
- # === Rdoc
18
- require 'rake/rdoctask'
19
- Rake::RDocTask.new do |rdoc|
20
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
21
-
22
- rdoc.rdoc_dir = 'rdoc'
23
- rdoc.title = "inventory #{version}"
24
- rdoc.rdoc_files.include('README*')
25
- rdoc.rdoc_files.include('lib/**/*.rb')
26
- end
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # encoding: utf-8
2
2
 
3
3
  require File.dirname(__FILE__) + '/../lib/yell'
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # encoding: utf-8
2
2
 
3
3
  require File.dirname(__FILE__) + '/../lib/yell'
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # encoding: utf-8
2
2
 
3
3
  require File.dirname(__FILE__) + '/../lib/yell'
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # encoding: utf-8
2
2
 
3
3
  require File.dirname(__FILE__) + '/../lib/yell'
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # encoding: utf-8
2
2
 
3
3
  require File.dirname(__FILE__) + '/../lib/yell'
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # encoding: utf-8
2
2
 
3
3
  require File.dirname(__FILE__) + '/../lib/yell'
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # encoding: utf-8
2
2
 
3
3
  require File.dirname(__FILE__) + '/../lib/yell'
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # encoding: utf-8
2
2
 
3
3
  require File.dirname(__FILE__) + '/../lib/yell'
4
4
 
@@ -12,22 +12,10 @@ module Yell #:nodoc:
12
12
 
13
13
  # The main method for calling the adapter.
14
14
  #
15
- # Adapter classes should provide their own implementation
16
- # of this method.
15
+ # The method receives the log `event` and determines whether to
16
+ # actually write or not.
17
17
  def write( event )
18
- nil
19
- end
20
-
21
- # Determine whether to write at the given severity.
22
- #
23
- # @example
24
- # write? :error
25
- #
26
- # @param [String,Symbol,Integer] severity The severity to ask if to write or not.
27
- #
28
- # @return [Boolean] true or false
29
- def write?( severity )
30
- @level.nil? || @level.at?( severity )
18
+ write!( event ) if write?( event )
31
19
  end
32
20
 
33
21
  # Close the adapter (stream, connection, etc).
@@ -35,7 +23,7 @@ module Yell #:nodoc:
35
23
  # Adapter classes should provide their own implementation
36
24
  # of this method.
37
25
  def close
38
- nil
26
+ raise 'Not implemented'
39
27
  end
40
28
 
41
29
  # Set the log level.
@@ -48,6 +36,28 @@ module Yell #:nodoc:
48
36
  @level = Yell::Level.new( severity )
49
37
  end
50
38
 
39
+ private
40
+
41
+ # The perform the actual write.
42
+ #
43
+ # Adapter classes should provide their own implementation
44
+ # of this method.
45
+ def write!( event )
46
+ raise 'Not implemented'
47
+ end
48
+
49
+ # Determine whether to write at the given severity.
50
+ #
51
+ # @example
52
+ # write? :error
53
+ #
54
+ # @param [String,Symbol,Integer] severity The severity to ask if to write or not.
55
+ #
56
+ # @return [Boolean] true or false
57
+ def write?( event )
58
+ @level.nil? || @level.at?( event.level )
59
+ end
60
+
51
61
  end
52
62
 
53
63
  end
@@ -21,13 +21,6 @@ module Yell #:nodoc:
21
21
  super( options, &block )
22
22
  end
23
23
 
24
- # @overload Close the file if date is expired
25
- def write( event )
26
- close if close?
27
-
28
- super( event )
29
- end
30
-
31
24
  # @overload Reset the file handle
32
25
  def close
33
26
  @filename = new_filename
@@ -38,6 +31,13 @@ module Yell #:nodoc:
38
31
 
39
32
  private
40
33
 
34
+ # @overload Close the file if date is expired
35
+ def write!( event )
36
+ close if close?
37
+
38
+ super( event )
39
+ end
40
+
41
41
  # Determines whether to close the file handle or not.
42
42
  #
43
43
  # It is based on the `:date_pattern` (can be passed as option upon initialize).
@@ -25,28 +25,9 @@ module Yell
25
25
 
26
26
  level options.fetch(:level, nil)
27
27
  format options.fetch(:format, nil)
28
- colorize! options.fetch(:colorize, false)
28
+ colorize options.fetch(:colorize, false)
29
29
 
30
- instance_eval &block if block
31
- end
32
-
33
- # Main method to calling the file adapter.
34
- #
35
- # The method formats the message and writes it to the file handle.
36
- #
37
- # @example
38
- # write( 'info', 'Hello World' )
39
- def write( event )
40
- message = @formatter.format( event )
41
-
42
- # colorize if applicable
43
- if colorize? and color = Colors[level]
44
- message = color + message + Colors['DEFAULT']
45
- end
46
-
47
- message << "\n" unless message[-1] == ?\n # add new line if there is none
48
-
49
- write!( message )
30
+ instance_eval( &block ) if block
50
31
  end
51
32
 
52
33
  # Set the format for your message.
@@ -59,20 +40,29 @@ module Yell
59
40
  end
60
41
 
61
42
  # Enable colorizing the log output.
62
- def colorize!( color = true )
43
+ def colorize( color = true )
63
44
  @colorize = color
64
45
  end
65
46
 
66
- # Determie whether to colorize the log output or nor
67
- #
68
- # @return [Boolean] true or false
69
- def colorize?; !!@colorize; end
47
+ def close
48
+ @stream.close if @stream.respond_to? :close
70
49
 
50
+ @stream = nil
51
+ end
71
52
 
72
53
  private
73
54
 
74
- # TODO: Implement Buffer to not flush immediately.
75
- def write!( message )
55
+ # The method formats the message and writes it to the file handle.
56
+ def write!( event )
57
+ message = @formatter.format( event )
58
+
59
+ # colorize if applicable
60
+ if colorize? and color = Colors[event.level]
61
+ message = color + message + Colors['DEFAULT']
62
+ end
63
+
64
+ message << "\n" unless message[-1] == ?\n # add new line if there is none
65
+
76
66
  stream.print( message )
77
67
  stream.flush
78
68
  rescue => e
@@ -82,6 +72,9 @@ module Yell
82
72
  raise( e, caller )
83
73
  end
84
74
 
75
+ # Determie whether to colorize the log output or nor
76
+ def colorize?; !!@colorize; end
77
+
85
78
  end
86
79
 
87
80
  end
@@ -42,7 +42,7 @@ module Yell #:nodoc:
42
42
  ExtendedFormat = "%d [%5L] %p %h : %m"
43
43
 
44
44
 
45
- def self.format( pattern, date_pattern )
45
+ def self.format( pattern, date_pattern = nil )
46
46
  Yell::Formatter.new( pattern, date_pattern )
47
47
  end
48
48
 
@@ -50,7 +50,6 @@ module Yell #:nodoc:
50
50
  # The +Formatter+ provides a handle to configure your log message style.
51
51
  class Formatter
52
52
 
53
- #:nodoc:
54
53
  PatternTable = {
55
54
  "m" => "event.message", # Message
56
55
  "l" => "event.level[0]", # Level (short), e.g.'I', 'W'
@@ -64,10 +63,14 @@ module Yell #:nodoc:
64
63
  "n" => "event.line" # Line where the logger was called
65
64
  }
66
65
 
67
- #:nodoc:
68
66
  PatternRegexp = /([^%]*)(%\d*)?([#{PatternTable.keys.join}])?(.*)/
69
67
 
70
68
 
69
+ # Initializes a new +Yell::Formatter+.
70
+ #
71
+ # Upon initialization it defines a format method. `format` takes
72
+ # a {Yell::Event} instance as agument in order to apply for desired log
73
+ # message formatting.
71
74
  def initialize( pattern = nil, date_pattern = nil )
72
75
  @pattern = pattern || Yell::DefaultFormat
73
76
  @date_pattern = date_pattern
@@ -75,7 +78,6 @@ module Yell #:nodoc:
75
78
  define!
76
79
  end
77
80
 
78
-
79
81
  private
80
82
 
81
83
  # defines the format method
@@ -49,7 +49,7 @@ module Yell #:nodoc:
49
49
  level @options[:level] if @options[:level]
50
50
 
51
51
  # eval the given block
52
- instance_eval &block if block
52
+ instance_eval( &block ) if block
53
53
 
54
54
  define!
55
55
  end
@@ -82,7 +82,7 @@ module Yell #:nodoc:
82
82
  end
83
83
 
84
84
  @adapters << Yell::Adapters[ type, options, &block ]
85
- rescue NameError => e
85
+ rescue NameError
86
86
  raise Yell::NoSuchAdapter, type
87
87
  end
88
88
 
@@ -136,7 +136,7 @@ module Yell #:nodoc:
136
136
 
137
137
  # Cycles all the adapters and writes the message
138
138
  def write( event )
139
- @adapters.each { |a| a.write(event) if a.write?(event.level) }
139
+ @adapters.each { |a| a.write(event) }
140
140
  end
141
141
 
142
142
  end
@@ -1,4 +1,4 @@
1
1
  module Yell #:nodoc:
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
 
4
4
  end
@@ -4,17 +4,11 @@ $:.unshift File.expand_path('../../lib', __FILE__)
4
4
  require 'yell'
5
5
 
6
6
  require 'rspec'
7
+ require 'rr'
7
8
  require 'timecop'
8
9
 
9
10
  RSpec.configure do |config|
10
-
11
- config.before do
12
- Yell.config.stub!( :yaml_file ).and_return( File.dirname(__FILE__) + '/config/yell.yml' )
13
- end
14
-
15
- config.after do
16
- Yell.config.reload! # to not run into caching problems during tests
17
- end
11
+ config.mock_framework = :rr
18
12
 
19
13
  end
20
14
 
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yell::Event do
4
+ let(:event) { Yell::Event.new 'INFO', 'Hello World!' }
5
+
6
+ context :level do
7
+ subject { event.level}
8
+
9
+ it { should == 'INFO' }
10
+ end
11
+
12
+ context :message do
13
+ subject { event.message }
14
+
15
+ it { should == 'Hello World!' }
16
+ end
17
+
18
+ context :time do
19
+ subject { event.time }
20
+
21
+ let(:time) { Time.now }
22
+
23
+ before do
24
+ Timecop.freeze( time )
25
+ end
26
+
27
+ it { should == time }
28
+ end
29
+
30
+ context :caller do
31
+ let(:file) { "event.rb" }
32
+ let(:line) { "123" }
33
+ let(:method) { "test_method" }
34
+
35
+ before do
36
+ any_instance_of( Yell::Event ) do |e|
37
+ mock( e ).caller(4) { ["#{file}:#{line}:in `#{method}'"] }
38
+ end
39
+ end
40
+
41
+ context :file do
42
+ subject { event.file }
43
+
44
+ it { should == file }
45
+ end
46
+
47
+ context :line do
48
+ subject { event.line }
49
+
50
+ it { should == line }
51
+ end
52
+
53
+ context :method do
54
+ subject { event.method }
55
+
56
+ it { should == method }
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yell::Formatter do
4
+
5
+ let( :formatter ) { Yell::Formatter.new(subject) }
6
+ let( :event ) { Yell::Event.new 'INFO', 'Hello World!' }
7
+ let( :time ) { Time.now }
8
+
9
+ let( :format ) { formatter.format(event) }
10
+
11
+ before do
12
+ Timecop.freeze( time )
13
+ end
14
+
15
+ context "%m" do
16
+ subject { "%m" }
17
+
18
+ it { format.should == "Hello World!" }
19
+ end
20
+
21
+ context "%l" do
22
+ subject { "%l" }
23
+
24
+ it { format.should == "I" }
25
+ end
26
+
27
+ context "%L" do
28
+ subject { "%L" }
29
+
30
+ it { format.should == "INFO" }
31
+ end
32
+
33
+ context "%d" do
34
+ subject { "%d" }
35
+
36
+ it { format.should == time.iso8601 }
37
+ end
38
+
39
+ context "%p" do
40
+ subject { "%p" }
41
+
42
+ it { format.should == Process.pid.to_s }
43
+ end
44
+
45
+ context "%h" do
46
+ subject { "%h" }
47
+
48
+ it { format.should == Socket.gethostname }
49
+ end
50
+
51
+ context "caller" do
52
+ let( :_caller ) { ["/path/to/file.rb:123:in `test_method'"] }
53
+
54
+ before do
55
+ any_instance_of( Yell::Event ) do |e|
56
+ mock(e).caller(4) { _caller }
57
+ end
58
+ end
59
+
60
+ context "%F" do
61
+ subject { "%F" }
62
+
63
+ it { format.should == "/path/to/file.rb" }
64
+ end
65
+
66
+ context "%f" do
67
+ subject { "%f" }
68
+
69
+ it { format.should == "file.rb" }
70
+ end
71
+
72
+ context "%M" do
73
+ subject { "%M" }
74
+
75
+ it { format.should == "test_method" }
76
+ end
77
+
78
+ context "%n" do
79
+ subject { "%n" }
80
+
81
+ it { format.should == "123" }
82
+ end
83
+ end
84
+
85
+ context "DefaultFormat" do
86
+ subject { Yell::DefaultFormat }
87
+
88
+ it { format.should == "#{time.iso8601} [ INFO] #{$$} : Hello World!" }
89
+ end
90
+
91
+ context "BasicFormat" do
92
+ subject { Yell::BasicFormat }
93
+
94
+ it { format.should == "I, #{time.iso8601} : Hello World!" }
95
+ end
96
+
97
+ context "ExtendedFormat" do
98
+ subject { Yell::ExtendedFormat }
99
+
100
+ it { format.should == "#{time.iso8601} [ INFO] #{$$} #{Socket.gethostname} : Hello World!" }
101
+ end
102
+
103
+ end
@@ -1,17 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Yell do
4
+ subject { Yell.new }
4
5
 
5
- describe "a new Yell instance" do
6
- let( :logger ) { Yell.new }
6
+ it { should be_kind_of Yell::Logger }
7
7
 
8
- it "should return a Yell::Logger" do
9
- logger.should be_kind_of( Yell::Logger )
10
- end
8
+ it "should raise NoSuchAdapter when adapter cant be loaded" do
9
+ lambda { Yell.new :unknownadapter }.should raise_error( Yell::NoSuchAdapter )
10
+ end
11
+
12
+ context :level do
13
+ subject { Yell.level }
14
+
15
+ it { should be_kind_of Yell::Level }
16
+ end
17
+
18
+ context :format do
19
+ subject { Yell.format( "%m" ) }
11
20
 
12
- it "should raise NoSuchAdapter when adapter cant be loaded" do
13
- lambda { Yell.new :unknownadapter }.should raise_error( Yell::NoSuchAdapter )
14
- end
21
+ it { should be_kind_of Yell::Formatter }
15
22
  end
16
23
 
17
24
  end
@@ -18,4 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency "rr"
21
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-22 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-03-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rr
16
+ requirement: &70253484861760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70253484861760
14
25
  description: An easy to use logging library to log into files and any other self-defined
15
26
  adapters
16
27
  email:
@@ -19,6 +30,7 @@ extensions: []
19
30
  extra_rdoc_files: []
20
31
  files:
21
32
  - .gitignore
33
+ - .travis.yml
22
34
  - Gemfile
23
35
  - LICENSE.txt
24
36
  - README.md
@@ -43,8 +55,9 @@ files:
43
55
  - lib/yell/level.rb
44
56
  - lib/yell/logger.rb
45
57
  - lib/yell/version.rb
46
- - spec/spec.opts
47
58
  - spec/spec_helper.rb
59
+ - spec/yell/event_spec.rb
60
+ - spec/yell/formatter_spec.rb
48
61
  - spec/yell_spec.rb
49
62
  - yell.gemspec
50
63
  homepage: http://rubygems.org/gems/yell
@@ -72,7 +85,8 @@ signing_key:
72
85
  specification_version: 3
73
86
  summary: Yell - Your Extensible Logging Library
74
87
  test_files:
75
- - spec/spec.opts
76
88
  - spec/spec_helper.rb
89
+ - spec/yell/event_spec.rb
90
+ - spec/yell/formatter_spec.rb
77
91
  - spec/yell_spec.rb
78
92
  has_rdoc:
@@ -1,3 +0,0 @@
1
- --colour
2
- --format progress
3
- --backtrace