yell 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
- Yell - Your Extensible Logging Library
1
+ **Yell - Your Extensible Logging Library**
2
+
3
+ [![Build Status](https://secure.travis-ci.org/rudionrails/yell.png?branch=master)](http://travis-ci.org/rudionrails/yell)
4
+
5
+ Yell works and is tested with ruby 1.8.7, 1.9.x, jruby 1.8 and 1.9 mode, rubinius 1.8 and 1.9 as well as ree.
2
6
 
3
- [![Build Status](https://secure.travis-ci.org/rudionrails/yell.png)](http://travis-ci.org/rudionrails/yell)
4
7
 
5
8
  ## Installation
6
9
 
@@ -16,6 +19,7 @@ Or in your Gemfile:
16
19
  gem "yell"
17
20
  ```
18
21
 
22
+
19
23
  ## Usage
20
24
 
21
25
  On the basics, Yell works just like any other logging library. However, it
@@ -45,10 +49,94 @@ Naturally, you can pass a `:filename` to Yell:
45
49
  logger = Yell.new "yell.log"
46
50
  ```
47
51
 
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.
52
+ ### Levels
53
+
54
+ Just like any other logging library, Yell allows you to define from which level
55
+ onwarns you want to write your log message. here are some examples to show how
56
+ you can combine those.
57
+
58
+ ##### Example: Write from `:info` onwards
59
+
60
+ ```ruby
61
+ logger = Yell.new STDOUT, :level => :info # write on :info, :warn, :error, :fatal
62
+ ```
63
+
64
+ ##### Example: Write on `:info` and `:error` only
65
+
66
+ ```ruby
67
+ logger - Yell.new STDOUT, :level => [:info, :error] # write on :info and :error only
68
+ ```
69
+
70
+ ##### Example: Write between :info and :error
71
+
72
+ ```ruby
73
+ logger = Yell.new STDOUT, :level => (:info..:error)
74
+
75
+ # NOTE: The Range might only work with 1.9 compatible rubies!
76
+ ```
77
+
78
+ There are more ways to set your logging level, please consult the
79
+ [wiki](https://github.com/rudionrails/yell/wiki) on that.
80
+
81
+
82
+ ### Adapters
83
+
84
+ Yell comes with various adapters already build-in. Those are the mainly IO-based
85
+ adapters for every day use. There are additional ones available as separate gems. Please
86
+ consult the [wiki](https://github.com/rudionrails/yell/wiki) on that - they are listed
87
+ there.
88
+
89
+ The standard adapters are:
90
+
91
+ **:stdout** or **STDOUT**: Messages will be written to STDOUT
92
+ **:stderr** or **STDERR**: Messages will be written to STDERR
93
+ **:file**: Messages will be written to a file
94
+ **:datefile**: Messages will be written to a timestamped file
95
+
96
+
97
+ Here are some short examples on how to combine them:
98
+
99
+ ##### Example: Notice messages go into `STDOUT` and error messages into `STDERR`
100
+
101
+ ```ruby
102
+ logger = Yell.new do
103
+ adapter STDOUT, :level => [:debug, :info, :warn]
104
+ adapter STDERR, :level => [:error, :fatal]
105
+ end
106
+ ```
107
+
108
+ ##### Example: Notice messages to into `application.log` and error messages into `error.log`
109
+
110
+ ```ruby
111
+ logger = Yell.new do
112
+ adapter :file, 'application.log', :level => [:debug, :info, :warn]
113
+ adapter :file, 'error.log', :level => [:error, :fatal]
114
+ end
115
+ ```
116
+
117
+ ##### Example: Every log severity is handled by a separate adapter and we ignore `:debug` and `:info` levels
118
+
119
+ ```ruby
120
+ logger = Yell.new do
121
+ level :warn # only start logging from :warn upwards
122
+
123
+ adapter :stdout, :level => [:warn]
124
+ adapter :datefile, 'error.log', :level => [:error]
125
+ adapter :datefile, 'fatal.log', :level => [:fatal]
126
+ end
127
+ ```
128
+
129
+ ## Further Readings
130
+
131
+ [How To: Setting The Log Level](https://github.com/rudionrails/yell/wiki/101-setting-the-log-level)
132
+ [How To: Formatting Log Messages](https://github.com/rudionrails/yell/wiki/101-formatting-log-messages)
133
+ [How To: Using Adapters](https://github.com/rudionrails/yell/wiki/101-using-adapters)
134
+ [How To: The Datefile Adapter](https://github.com/rudionrails/yell/wiki/101-the-datefile-adapter)
135
+ [How To: Different Adapters for Different Log Levels](https://github.com/rudionrails/yell/wiki/101-different-adapters-for-different-log-levels)
136
+
137
+
138
+ You can find further examples and additional adapters in the [wiki](https://github.com/rudionrails/yell/wiki).
139
+ or have a look into the examples folder.
52
140
 
53
141
 
54
142
  Copyright © 2011-2012 Rudolf Schmidt, released under the MIT license
@@ -10,7 +10,12 @@ module Yell #:nodoc:
10
10
  # by the {Yell::Logger}.
11
11
  class Base
12
12
 
13
+ # Accessor to the options
14
+ attr_reader :options
15
+
13
16
  def initialize( options = {}, &block )
17
+ @options = options
18
+
14
19
  level options[:level]
15
20
 
16
21
  instance_eval( &block ) if block
@@ -18,39 +18,22 @@ module Yell #:nodoc:
18
18
 
19
19
  @date = nil # default; do not override --R
20
20
 
21
- keep options[:keep]
22
-
23
21
  super
24
22
  end
25
23
 
26
24
  # @overload Reset the file handle
27
25
  def close
28
- @filename = filename_from( @date )
26
+ @filename = new_filename
29
27
 
30
28
  super
31
29
  end
32
30
 
33
- # Set the amount of logfiles to keep when rolling over
34
- #
35
- # @example Keep the last 5 logfiles
36
- # keep 5
37
- def keep( n = nil )
38
- @keep = n
39
- end
40
31
 
41
32
  private
42
33
 
43
34
  # @overload Close the file if date is expired
44
35
  def write!( event )
45
- if close?
46
- close
47
-
48
- unless ::File.exist?( @filename )
49
- cleanup if cleanup?
50
-
51
- stream.print( "# -*- #{@date.iso8601} (#{@date.to_f}) [#{@date_pattern}] -*-\n" )
52
- end
53
- end
36
+ close if close?
54
37
 
55
38
  super( event )
56
39
  end
@@ -61,12 +44,8 @@ module Yell #:nodoc:
61
44
  # If the current time hits the pattern, it closes the file stream.
62
45
  #
63
46
  # @return [Boolean] true or false
64
- #
65
- # TODO: This method causes the datefile adapter to be twice as slow as the file.
66
- # Let's refactor this.
67
47
  def close?
68
- _date = Time.now
69
-
48
+ _date = Time.now.strftime( @date_pattern )
70
49
  if !@stream or _date != @date
71
50
  @date = _date
72
51
  return true
@@ -75,31 +54,9 @@ module Yell #:nodoc:
75
54
  false
76
55
  end
77
56
 
78
- def cleanup
79
- files = Dir[ @file_basename.sub( /(\.\w+)?$/, ".*\\1" ) ].map do |f|
80
- [ f, metadata_from(f).last ]
81
- end.select do |(f, p)|
82
- @date_pattern == p
83
- end
84
-
85
- ::File.unlink( *files.map(&:first)[0..-(@keep)] )
86
- end
87
-
88
- def cleanup?
89
- !!@keep
90
- end
91
-
92
57
  # Sets the filename with the `:date_pattern` appended to it.
93
- def filename_from( date )
94
- @file_basename.sub( /(\.\w+)?$/, ".#{date.strftime(@date_pattern)}\\1" )
95
- end
96
-
97
- def metadata_from( file )
98
- if m = ::File.open( file, &:readline ).match( /^# -\*- (.+) \((\d+\.\d+)\) \[(.+)\] -\*-$/ )
99
- [ Time.at( m[2].to_f ), m[3] ]
100
- else
101
- [ ::File.mtime( file ), "" ]
102
- end
58
+ def new_filename
59
+ @file_basename.sub( /(\.\w+)?$/, ".#{@date}\\1" )
103
60
  end
104
61
 
105
62
  end
@@ -108,4 +65,3 @@ module Yell #:nodoc:
108
65
 
109
66
  end
110
67
  end
111
-
@@ -1,4 +1,4 @@
1
1
  module Yell #:nodoc:
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
 
4
4
  end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yell::Adapters::Base do
4
+
5
+ context "initialize with :level" do
6
+ before do
7
+ any_instance_of( Yell::Adapters::Base ) do |base|
8
+ mock( base ).level( :info )
9
+ end
10
+ end
11
+
12
+ it "should set the level" do
13
+ Yell::Adapters::Base.new :level => :info
14
+ end
15
+ end
16
+
17
+ context "insitialize with :block" do
18
+ context :level do
19
+ before do
20
+ any_instance_of( Yell::Adapters::Base ) do |base|
21
+ mock( base ).level( :info )
22
+ end
23
+ end
24
+
25
+ it "should set the level" do
26
+ Yell::Adapters::Base.new :level => :info
27
+ end
28
+ end
29
+ end
30
+
31
+ context :options do
32
+ let( :options ) { { :my => :options } }
33
+ let( :adapter ) { Yell::Adapters::Base.new( options ) }
34
+
35
+ it { options.should == options }
36
+ end
37
+
38
+ context :write do
39
+ subject { Yell::Adapters::Base.new :level => :info }
40
+
41
+ it "should delegate :event to :write!" do
42
+ event = Yell::Event.new( "INFO", "Hello World!" )
43
+
44
+ mock( subject ).write!( event )
45
+
46
+ subject.write( event )
47
+ end
48
+
49
+ it "should not write when event does not have the right level" do
50
+ event = Yell::Event.new( "DEBUG", "Hello World!" )
51
+
52
+ dont_allow( subject ).write!( event )
53
+
54
+ subject.write( event )
55
+ end
56
+ end
57
+
58
+ context :close do
59
+ subject { Yell::Adapters::Base.new.close }
60
+
61
+ it "should raise" do
62
+ lambda { subject }.should raise_error("Not implemented" )
63
+ end
64
+ end
65
+
66
+ end
67
+
@@ -7,10 +7,10 @@ Gem::Specification.new do |s|
7
7
  s.version = Yell::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Rudolf Schmidt"]
10
-
10
+
11
11
  s.homepage = "http://rubygems.org/gems/yell"
12
12
  s.summary = %q{Yell - Your Extensible Logging Library }
13
- s.description = %q{An easy to use logging library to log into files and any other self-defined adapters}
13
+ s.description = %q{Yell - Your Extensible Logging Library. Define multiple adapters, various log level combinations or message formatting options like you've never done before}
14
14
 
15
15
  s.rubyforge_project = "yell"
16
16
 
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.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-29 00:00:00.000000000 Z
12
+ date: 2012-03-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rr
16
- requirement: &70163680872100 !ruby/object:Gem::Requirement
16
+ requirement: &70222528328160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,9 +21,9 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70163680872100
25
- description: An easy to use logging library to log into files and any other self-defined
26
- adapters
24
+ version_requirements: *70222528328160
25
+ description: Yell - Your Extensible Logging Library. Define multiple adapters, various
26
+ log level combinations or message formatting options like you've never done before
27
27
  email:
28
28
  executables: []
29
29
  extensions: []
@@ -56,6 +56,7 @@ files:
56
56
  - lib/yell/logger.rb
57
57
  - lib/yell/version.rb
58
58
  - spec/spec_helper.rb
59
+ - spec/yell/adapters/base_spec.rb
59
60
  - spec/yell/event_spec.rb
60
61
  - spec/yell/formatter_spec.rb
61
62
  - spec/yell/level_spec.rb
@@ -88,6 +89,7 @@ specification_version: 3
88
89
  summary: Yell - Your Extensible Logging Library
89
90
  test_files:
90
91
  - spec/spec_helper.rb
92
+ - spec/yell/adapters/base_spec.rb
91
93
  - spec/yell/event_spec.rb
92
94
  - spec/yell/formatter_spec.rb
93
95
  - spec/yell/level_spec.rb