yell 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -3
- data/lib/yell/adapters/datefile.rb +2 -2
- data/lib/yell/logger.rb +4 -2
- data/lib/yell/version.rb +1 -1
- data/spec/spec_helper.rb +8 -0
- data/spec/threaded/yell_spec.rb +1 -1
- data/spec/yell/adapters/datefile_spec.rb +25 -14
- data/spec/yell/adapters/file_spec.rb +12 -1
- data/spec/yell/logger_spec.rb +8 -0
- metadata +2 -2
data/.travis.yml
CHANGED
@@ -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
|
31
|
-
self.symlink = options.fetch(:symlink,
|
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
|
data/lib/yell/logger.rb
CHANGED
@@ -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.
|
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(
|
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 )
|
data/lib/yell/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -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
|
|
data/spec/threaded/yell_spec.rb
CHANGED
@@ -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 + '
|
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
|
-
|
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
|
-
|
76
|
+
it "should symlink upon rollover" do
|
75
77
|
adapter.write( event )
|
76
78
|
|
77
|
-
|
78
|
-
|
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
|
|
data/spec/yell/logger_spec.rb
CHANGED
@@ -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.
|
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:
|
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
|