yell 1.2.1 → 1.2.2

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.
@@ -3,9 +3,9 @@ language: ruby
3
3
  script: "rspec"
4
4
 
5
5
  rvm:
6
- - ruby-1.8.7
7
- - ruby-1.9.2
8
- - ruby-1.9.3
6
+ - 1.8.7
7
+ - 1.9.2
8
+ - 1.9.3
9
9
  - ruby-head
10
10
  - jruby-18mode
11
11
  - jruby-19mode
@@ -27,8 +27,8 @@ module Yell #:nodoc:
27
27
  # check whether to cleanup old files of the same pattern (default false)
28
28
  self.keep = options.fetch(:keep, false)
29
29
 
30
- # check whether to symlink the otiginal filename (default false)
31
- self.symlink = options.fetch(:symlink, false)
30
+ # check whether to symlink the otiginal filename (default true)
31
+ self.symlink = options.fetch(:symlink, true)
32
32
 
33
33
  @original_filename = ::File.expand_path options.fetch(:filename, default_filename)
34
34
  options[:filename] = @original_filename
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'pathname'
4
+
3
5
  module Yell #:nodoc:
4
6
 
5
7
  # The +Yell::Logger+ is your entrypoint. Anything onwards is derived from here.
@@ -44,7 +46,7 @@ module Yell #:nodoc:
44
46
  _extract_adapters!( @options )
45
47
 
46
48
  # check if filename was given as argument and put it into the @options
47
- if args.last.is_a?( String )
49
+ if [String, Pathname].include?(args.last.class)
48
50
  @options[:filename] = args.pop unless @options[:filename]
49
51
  end
50
52
 
@@ -88,7 +90,7 @@ module Yell #:nodoc:
88
90
  # @raise [Yell::NoSuchAdapter] Will be thrown when the adapter is not defined
89
91
  def adapter( type = :file, *args, &block )
90
92
  options = [@options, *args].inject( Hash.new ) do |h, c|
91
- h.merge( c.is_a?(String) ? {:filename => c} : c )
93
+ h.merge( [String, Pathname].include?(c.class) ? {:filename => c} : c )
92
94
  end
93
95
 
94
96
  @adapters << Yell::Adapters.new( type, options, &block )
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Yell #:nodoc:
4
- VERSION = "1.2.1"
4
+ VERSION = "1.2.2"
5
5
 
6
6
  end
7
7
 
@@ -14,17 +14,25 @@ RSpec.configure do |config|
14
14
 
15
15
  config.before do
16
16
  Yell::Repository.loggers.clear
17
+
17
18
  Dir[ fixture_path + "/*.log" ].each { |f| File.delete f }
18
19
  end
19
20
 
20
21
  config.after do
22
+ # release time after each test
23
+ Timecop.return
21
24
  end
22
25
 
26
+
23
27
  private
24
28
 
25
29
  def fixture_path
26
30
  File.expand_path( "fixtures", File.dirname(__FILE__) )
27
31
  end
28
32
 
33
+ def datefile_filename( pattern = Yell::Adapters::Datefile::DefaultDatePattern )
34
+ fixture_path + "/test.#{Time.now.strftime(pattern)}.log"
35
+ end
36
+
29
37
  end
30
38
 
@@ -82,7 +82,7 @@ describe "running Yell multi-threaded" do
82
82
  Timecop.freeze( date + 86400*count )
83
83
  sleep 0.3
84
84
 
85
- files = Dir[ fixture_path + '/*.log' ]
85
+ files = Dir[ fixture_path + '/*.*.log' ]
86
86
  files.size.should == 2
87
87
 
88
88
  # files.last.should match( datefile_pattern_for(Time.now) ) # today
@@ -9,7 +9,7 @@ describe Yell::Adapters::Datefile do
9
9
  end
10
10
 
11
11
  describe :filename do
12
- let( :adapter ) { Yell::Adapters::Datefile.new(:filename => filename) }
12
+ let( :adapter ) { Yell::Adapters::Datefile.new(:filename => filename, :symlink => false) }
13
13
 
14
14
  it "should be replaced with date_pattern" do
15
15
  adapter.write( event )
@@ -41,7 +41,7 @@ describe Yell::Adapters::Datefile do
41
41
  end
42
42
 
43
43
  describe :keep do
44
- let( :adapter ) { Yell::Adapters::Datefile.new(:keep => 2, :filename => filename, :date_pattern => "%M") }
44
+ let( :adapter ) { Yell::Adapters::Datefile.new(:keep => 2, :filename => filename, :symlink => false, :date_pattern => "%M") }
45
45
 
46
46
  it "should keep the specified number or files upon rollover" do
47
47
  adapter.write( event )
@@ -60,22 +60,38 @@ describe Yell::Adapters::Datefile do
60
60
  end
61
61
 
62
62
  describe :symlink do
63
- let( :adapter ) { Yell::Adapters::Datefile.new(:symlink => true, :filename => filename, :date_pattern => "%M") }
64
63
  let( :time ) { Time.now }
64
+ before { Timecop.freeze(time) }
65
+
66
+ context "default (true)" do
67
+ let( :adapter ) { Yell::Adapters::Datefile.new(:filename => filename, :date_pattern => "%M") }
65
68
 
66
- it "should symlink to the orignal given :filename" do
67
- Timecop.freeze( time ) do
69
+ it "should create the sylink the original filename" do
68
70
  adapter.write( event )
69
71
 
70
72
  File.symlink?( filename ).should be_true
71
73
  File.readlink( filename ).should == datefile_filename( adapter.date_pattern )
72
74
  end
73
75
 
74
- Timecop.freeze( time + 60 ) do
76
+ it "should symlink upon rollover" do
75
77
  adapter.write( event )
76
78
 
77
- File.symlink?( filename ).should be_true
78
- File.readlink( filename ).should == datefile_filename( adapter.date_pattern )
79
+ Timecop.freeze( time + 120 ) do
80
+ adapter.write( event )
81
+
82
+ File.symlink?( filename ).should be_true
83
+ File.readlink( filename ).should == datefile_filename( adapter.date_pattern )
84
+ end
85
+ end
86
+ end
87
+
88
+ context "when set to false" do
89
+ let( :adapter ) { Yell::Adapters::Datefile.new(:symlink => false, :filename => filename, :date_pattern => "%M") }
90
+
91
+ it "should not create the sylink the original filename" do
92
+ adapter.write( event )
93
+
94
+ File.symlink?( filename ).should be_false
79
95
  end
80
96
  end
81
97
  end
@@ -102,10 +118,5 @@ describe Yell::Adapters::Datefile do
102
118
  end
103
119
  end
104
120
 
105
-
106
- private
107
-
108
- def datefile_filename( pattern = Yell::Adapters::Datefile::DefaultDatePattern )
109
- fixture_path + "/test.#{Time.now.strftime(pattern)}.log"
110
- end
111
121
  end
122
+
@@ -29,7 +29,7 @@ describe Yell::Adapters::File do
29
29
  end
30
30
  end
31
31
 
32
- context "with given filename" do
32
+ context "with given :filename" do
33
33
  let( :filename ) { fixture_path + '/filename.log' }
34
34
  let( :adapter ) { Yell::Adapters::File.new( :filename => filename ) }
35
35
 
@@ -40,6 +40,17 @@ describe Yell::Adapters::File do
40
40
  end
41
41
  end
42
42
 
43
+ context "with given :pathname" do
44
+ let( :pathname ) { Pathname.new(fixture_path).join('filename.log') }
45
+ let( :adapter ) { Yell::Adapters::File.new( :filename => pathname ) }
46
+
47
+ it "should accept pathanme as filename" do
48
+ mock( File ).open( pathname.to_s, File::WRONLY|File::APPEND|File::CREAT ) { devnull }
49
+
50
+ adapter.write( event )
51
+ end
52
+ end
53
+
43
54
  context :sync do
44
55
  let( :adapter ) { Yell::Adapters::File.new }
45
56
 
@@ -66,6 +66,14 @@ describe Yell::Logger do
66
66
  end
67
67
  end
68
68
 
69
+ context "initialize with a :filename of Pathname type" do
70
+ it "should call adapter with :file" do
71
+ mock.proxy( Yell::Adapters::File ).new( :filename => Pathname.new('test.log') )
72
+
73
+ Yell::Logger.new Pathname.new('test.log')
74
+ end
75
+ end
76
+
69
77
  context "initialize with a :stdout adapter" do
70
78
  before do
71
79
  mock.proxy( Yell::Adapters::Stdout ).new( anything )
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: 1.2.1
4
+ version: 1.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-27 00:00:00.000000000 Z
12
+ date: 2013-01-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Yell - Your Extensible Logging Library. Define multiple adapters, various
15
15
  log level combinations or message formatting options like you've never done before