yell 0.13.3 → 0.13.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -72,16 +72,22 @@ module Yell #:nodoc:
72
72
  end
73
73
 
74
74
  # Loads a config from a YAML file
75
+ #
76
+ # @return [Yell::Logger] The logger instance
75
77
  def load!( file )
76
- Yell.new Yell::Configuration.load!( file )
78
+ Yell.new Yell::Configuration.load!(file)
77
79
  end
78
80
 
79
81
  def env #:nodoc:
82
+ return ENV['YELL_ENV'] if ENV.key? 'YELL_ENV'
83
+ return ENV['RACK_ENV'] if ENV.key? 'RACK_ENV'
84
+ return ENV['RAILS_ENV'] if ENV.key? 'RAILS_ENV'
85
+
80
86
  if defined?( Rails )
81
- return Rails.env
87
+ Rails.env
88
+ else
89
+ 'development'
82
90
  end
83
-
84
- ENV['YELL_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
85
91
  end
86
92
 
87
93
  def _deprecate( version, message, options = {} ) #:nodoc:
@@ -92,7 +98,7 @@ module Yell #:nodoc:
92
98
  _warn( *messages )
93
99
  end
94
100
 
95
- def _warn( *messages )
101
+ def _warn( *messages ) #:nodoc:
96
102
  $stderr.puts "[Yell] " + messages.join( "\n" )
97
103
  rescue
98
104
  # do nothing
@@ -16,7 +16,7 @@ module Yell #:nodoc:
16
16
 
17
17
 
18
18
  setup do |options|
19
- @date = nil # default; do not override --R
19
+ @date, @date_strftime = nil, nil # default; do not override --R
20
20
 
21
21
  self.date_pattern = options.fetch(:date_pattern, DefaultDatePattern)
22
22
  self.keep = options.fetch(:keep, 0)
@@ -39,11 +39,10 @@ module Yell #:nodoc:
39
39
  return unless close? # do nothing when not closing
40
40
  close
41
41
 
42
- return if ::File.exist?( @filename ) # do nothing when file ready present
43
-
44
42
  cleanup! if cleanup?
45
43
  symlink! if symlink?
46
44
 
45
+ return if ::File.exist?( @filename ) # exit when file ready present
47
46
  stream.puts( Metadata.call(@date, date_pattern) )
48
47
  end
49
48
 
@@ -81,17 +80,18 @@ module Yell #:nodoc:
81
80
 
82
81
  private
83
82
 
84
- # Determines whether to close the file handle or not.
83
+ # Determine whether to close the file handle or not.
85
84
  #
86
85
  # It is based on the `:date_pattern` (can be passed as option upon initialize).
87
86
  # If the current time hits the pattern, it closes the file stream.
88
87
  #
89
88
  # @return [Boolean] true or false
90
89
  def close?
91
- _date = Time.now
90
+ _date = Time.now
91
+ _date_strftime = _date.strftime(date_pattern)
92
92
 
93
- if @stream.nil? or _date != @date
94
- @date = _date
93
+ if @stream.nil? or _date_strftime != @date_strftime
94
+ @date, @date_strftime = _date, _date_strftime
95
95
  return true
96
96
  end
97
97
 
@@ -114,8 +114,9 @@ module Yell #:nodoc:
114
114
  end
115
115
 
116
116
  def symlink!
117
- ::File.unlink( @original_filename ) if ::File.symlink?( @original_filename )
117
+ return if ::File.symlink?(@original_filename) && ::File.readlink(@original_filename) == @filename # do nothing, because symlink is already correct
118
118
 
119
+ ::File.unlink( @original_filename ) if ::File.exist?( @original_filename )
119
120
  ::File.symlink( @filename, @original_filename )
120
121
  end
121
122
 
@@ -23,6 +23,7 @@ module Yell #:nodoc:
23
23
  @stream = ::File.open( @filename, ::File::WRONLY|::File::APPEND|::File::CREAT )
24
24
  @stream.sync = true
25
25
 
26
+
26
27
  @stream
27
28
  end
28
29
 
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Yell #:nodoc:
4
- VERSION = "0.13.3"
4
+ VERSION = "0.13.4"
5
5
 
6
6
  end
7
7
 
@@ -21,7 +21,7 @@ describe Yell::Adapters::Datefile do
21
21
  mock( File ).open( datefile_filename, anything ) { File.new('/dev/null', 'w') }
22
22
 
23
23
  adapter.write( event )
24
- adapter.write( event )
24
+ Timecop.freeze( Time.now + 10 ) { adapter.write( event ) }
25
25
  end
26
26
 
27
27
  context "rollover" do
@@ -61,5 +61,53 @@ describe Yell do
61
61
  end
62
62
  end
63
63
 
64
+ context :env do
65
+ subject { Yell.env }
66
+
67
+ it "should default to YELL_ENV" do
68
+ subject.should == 'test'
69
+ end
70
+
71
+ context "fallback to RACK_ENV" do
72
+ before do
73
+ stub( ENV ).key?( 'YELL_ENV' ) { false }
74
+ mock( ENV ).key?( 'RACK_ENV' ) { true }
75
+
76
+ ENV['RACK_ENV'] = 'rack'
77
+ end
78
+
79
+ after { ENV.delete 'RACK_ENV' }
80
+
81
+ it { should == 'rack' }
82
+ end
83
+
84
+ context "fallback to RAILS_ENV" do
85
+ before do
86
+ stub( ENV ).key?( 'YELL_ENV' ) { false }
87
+ stub( ENV ).key?( 'RACK_ENV' ) { false }
88
+ mock( ENV ).key?( 'RAILS_ENV' ) { true }
89
+
90
+ ENV['RAILS_ENV'] = 'rails'
91
+ end
92
+
93
+ after { ENV.delete 'RAILS_ENV' }
94
+
95
+ it { should == 'rails' }
96
+ end
97
+
98
+ it "should fallback to Rails.env" do
99
+ end
100
+
101
+ context "fallback to development" do
102
+ before do
103
+ stub( ENV ).key?( 'YELL_ENV' ) { false }
104
+ stub( ENV ).key?( 'RACK_ENV' ) { false }
105
+ stub( ENV ).key?( 'RAILS_ENV' ) { false }
106
+ end
107
+
108
+ it { should == 'development' }
109
+ end
110
+ end
111
+
64
112
  end
65
113
 
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.13.3
4
+ version: 0.13.4
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-09-13 00:00:00.000000000 Z
12
+ date: 2012-09-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
@@ -105,3 +105,4 @@ test_files:
105
105
  - spec/yell/logger_spec.rb
106
106
  - spec/yell/repository_spec.rb
107
107
  - spec/yell_spec.rb
108
+ has_rdoc: