logging 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ == 1.5.2 / 2011-07-07
2
+
3
+ Bug Fixes
4
+ - Changing working directory breaks rolling file appenders [issue #8]
5
+
1
6
  == 1.5.1 / 2011-06-03
2
7
 
3
8
  Bug Fixes
@@ -42,6 +42,8 @@ module Logging::Appenders
42
42
  def initialize( name, opts = {} )
43
43
  @fn = opts.getopt(:filename, name)
44
44
  raise ArgumentError, 'no filename was given' if @fn.nil?
45
+
46
+ @fn = ::File.expand_path(@fn)
45
47
  self.class.assert_valid_logfile(@fn)
46
48
  @mode = opts.getopt(:truncate) ? 'w' : 'a'
47
49
 
@@ -69,8 +69,10 @@ module Logging::Appenders
69
69
  def initialize( name, opts = {} )
70
70
  # raise an error if a filename was not given
71
71
  @fn = opts.getopt(:filename, name)
72
- @fn_copy = @fn + '._copy_'
73
72
  raise ArgumentError, 'no filename was given' if @fn.nil?
73
+
74
+ @fn = ::File.expand_path(@fn)
75
+ @fn_copy = @fn + '._copy_'
74
76
  ::Logging::Appenders::File.assert_valid_logfile(@fn)
75
77
 
76
78
  # grab our options
@@ -43,7 +43,7 @@ module TestAppenders
43
43
  log = File.join(TMP, 'file.log')
44
44
  appender = Logging.appenders.file(NAME, 'filename' => log)
45
45
  assert_equal 'logfile', appender.name
46
- assert_equal log, appender.filename
46
+ assert_equal ::File.expand_path(log), appender.filename
47
47
  appender << "This will be the first line\n"
48
48
  appender << "This will be the second line\n"
49
49
  appender.flush
@@ -56,7 +56,7 @@ module TestAppenders
56
56
 
57
57
  appender = Logging.appenders.file(NAME, :filename => log)
58
58
  assert_equal 'logfile', appender.name
59
- assert_equal log, appender.filename
59
+ assert_equal ::File.expand_path(log), appender.filename
60
60
  appender << "This will be the third line\n"
61
61
  appender.flush
62
62
  File.open(log, 'r') do |file|
@@ -79,7 +79,23 @@ module TestAppenders
79
79
  cleanup
80
80
  end
81
81
 
82
- private
82
+ def test_changing_directories
83
+ log = File.join(TMP, 'file.log')
84
+ appender = Logging.appenders.file(NAME, 'filename' => log)
85
+
86
+ assert_equal 'logfile', appender.name
87
+ assert_equal ::File.expand_path(log), appender.filename
88
+
89
+ begin
90
+ pwd = Dir.pwd
91
+ Dir.chdir TMP
92
+ assert_nothing_raised { appender.reopen }
93
+ ensure
94
+ Dir.chdir pwd
95
+ end
96
+ end
97
+
98
+ private
83
99
  def cleanup
84
100
  unless Logging.appenders[NAME].nil?
85
101
  Logging.appenders[NAME].close false
@@ -87,9 +103,8 @@ module TestAppenders
87
103
  end
88
104
  end
89
105
 
90
- end # class TestFile
106
+ end # TestFile
91
107
 
92
- end # module TestAppenders
93
- end # module TestLogging
108
+ end # TestAppenders
109
+ end # TestLogging
94
110
 
95
- # EOF
@@ -13,9 +13,9 @@ module TestAppenders
13
13
  super
14
14
  Logging.init
15
15
 
16
- @fn = File.join(TMP, 'test.log')
17
- @fn_fmt = File.join(TMP, 'test.%d.log')
18
- @glob = File.join(TMP, '*.log')
16
+ @fn = File.expand_path('test.log', TMP)
17
+ @fn_fmt = File.expand_path('test.%d.log', TMP)
18
+ @glob = File.expand_path('*.log', TMP)
19
19
  end
20
20
 
21
21
  def test_initialize
@@ -194,7 +194,24 @@ module TestAppenders
194
194
  assert_equal 100, File.size(@fn)
195
195
  end
196
196
 
197
- private
197
+ def test_changing_directories
198
+ ap = Logging.appenders.rolling_file(NAME, :filename => @fn, :size => 100)
199
+
200
+ begin
201
+ pwd = Dir.pwd
202
+ Dir.chdir TMP
203
+
204
+ ap << 'X' * 100; ap.flush
205
+ assert_equal 1, Dir.glob(@glob).length
206
+
207
+ ap << 'X'; ap.flush
208
+ assert_equal 2, Dir.glob(@glob).length
209
+ ensure
210
+ Dir.chdir pwd
211
+ end
212
+ end
213
+
214
+ private
198
215
  def cleanup
199
216
  unless Logging.appenders[NAME].nil?
200
217
  Logging.appenders[NAME].close false
@@ -202,8 +219,7 @@ module TestAppenders
202
219
  end
203
220
  end
204
221
 
205
- end # class TestRollingFile
206
- end # module TestAppenders
207
- end # module TestLogging
222
+ end # TestRollingFile
223
+ end # TestAppenders
224
+ end # TestLogging
208
225
 
209
- # EOF
@@ -29,15 +29,14 @@ module LoggingTestCase
29
29
  FileUtils.rm_rf TMP
30
30
  FileUtils.mkdir TMP
31
31
  end
32
-
32
+
33
33
  def teardown
34
34
  super
35
35
  FileUtils.rm_rf TMP
36
36
  end
37
37
 
38
- end # module LoggingTestCase
39
- end # module TestLogging
38
+ end # LoggingTestCase
39
+ end # TestLogging
40
40
 
41
- end # unless defined?
41
+ end # defined?
42
42
 
43
- # EOF
@@ -57,7 +57,7 @@ module TestLogging
57
57
  logfile = ::Logging::Appenders['logfile']
58
58
  assert_instance_of ::Logging::Appenders::File, logfile
59
59
  assert_equal 0, logfile.level
60
- assert_equal 'tmp/temp.log', logfile.instance_variable_get(:@fn)
60
+ assert_equal ::File.expand_path('tmp/temp.log'), logfile.instance_variable_get(:@fn)
61
61
 
62
62
  layout = logfile.layout
63
63
  assert_instance_of ::Logging::Layouts::Pattern, layout
@@ -1 +1 @@
1
- 1.5.1
1
+ 1.5.2
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logging
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 5
9
- - 1
10
- version: 1.5.1
9
+ - 2
10
+ version: 1.5.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tim Pease
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-03 00:00:00 -06:00
18
+ date: 2011-07-07 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency