logging 2.2.2 → 2.3.0

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.
@@ -14,10 +14,10 @@ module TestAppenders
14
14
  super
15
15
  Logging.init
16
16
 
17
- FileUtils.mkdir [File.join(TMP, 'dir'), File.join(TMP, 'uw_dir')]
18
- FileUtils.chmod 0555, File.join(TMP, 'uw_dir')
19
- FileUtils.touch File.join(TMP, 'uw_file')
20
- FileUtils.chmod 0444, File.join(TMP, 'uw_file')
17
+ FileUtils.mkdir [File.join(@tmpdir, 'dir'), File.join(@tmpdir, 'uw_dir')]
18
+ FileUtils.chmod 0555, File.join(@tmpdir, 'uw_dir')
19
+ FileUtils.touch File.join(@tmpdir, 'uw_file')
20
+ FileUtils.chmod 0444, File.join(@tmpdir, 'uw_file')
21
21
  end
22
22
 
23
23
  def test_factory_method_validates_input
@@ -27,27 +27,27 @@ module TestAppenders
27
27
  end
28
28
 
29
29
  def test_class_assert_valid_logfile
30
- log = File.join(TMP, 'uw_dir', 'file.log')
30
+ log = File.join(@tmpdir, 'uw_dir', 'file.log')
31
31
  assert_raise(ArgumentError) do
32
32
  Logging.appenders.file(log).class.assert_valid_logfile(log)
33
33
  end
34
34
 
35
- log = File.join(TMP, 'dir')
35
+ log = File.join(@tmpdir, 'dir')
36
36
  assert_raise(ArgumentError) do
37
37
  Logging.appenders.file(log).class.assert_valid_logfile(log)
38
38
  end
39
39
 
40
- log = File.join(TMP, 'uw_file')
40
+ log = File.join(@tmpdir, 'uw_file')
41
41
  assert_raise(ArgumentError) do
42
42
  Logging.appenders.file(log).class.assert_valid_logfile(log)
43
43
  end
44
44
 
45
- log = File.join(TMP, 'file.log')
45
+ log = File.join(@tmpdir, 'file.log')
46
46
  assert Logging.appenders.file(log).class.assert_valid_logfile(log)
47
47
  end
48
48
 
49
49
  def test_initialize
50
- log = File.join(TMP, 'file.log')
50
+ log = File.join(@tmpdir, 'file.log')
51
51
  appender = Logging.appenders.file(NAME, :filename => log)
52
52
  assert_equal 'logfile', appender.name
53
53
  assert_equal ::File.expand_path(log), appender.filename
@@ -87,7 +87,7 @@ module TestAppenders
87
87
  end
88
88
 
89
89
  def test_changing_directories
90
- log = File.join(TMP, 'file.log')
90
+ log = File.join(@tmpdir, 'file.log')
91
91
  appender = Logging.appenders.file(NAME, :filename => log)
92
92
 
93
93
  assert_equal 'logfile', appender.name
@@ -95,29 +95,45 @@ module TestAppenders
95
95
 
96
96
  begin
97
97
  pwd = Dir.pwd
98
- Dir.chdir TMP
98
+ Dir.chdir @tmpdir
99
99
  assert_nothing_raised { appender.reopen }
100
100
  ensure
101
101
  Dir.chdir pwd
102
102
  end
103
103
  end
104
104
 
105
- if Object.const_defined? :Encoding
105
+ def test_encoding
106
+ log = File.join(@tmpdir, 'file-encoding.log')
107
+ appender = Logging.appenders.file(NAME, :filename => log, :encoding => 'ASCII')
106
108
 
107
- def test_encoding
108
- log = File.join(TMP, 'file-encoding.log')
109
- appender = Logging.appenders.file(NAME, :filename => log, :encoding => 'ASCII')
109
+ appender << "A normal line of text\n"
110
+ appender << "ümlaut\n"
111
+ appender.close
110
112
 
111
- appender << "A normal line of text\n"
112
- appender << "ümlaut\n"
113
- appender.close
113
+ lines = File.readlines(log, :encoding => 'UTF-8')
114
+ assert_equal "A normal line of text\n", lines[0]
115
+ assert_equal "ümlaut\n", lines[1]
114
116
 
115
- lines = File.readlines(log, :encoding => 'UTF-8')
116
- assert_equal "A normal line of text\n", lines[0]
117
- assert_equal "ümlaut\n", lines[1]
117
+ cleanup
118
+ end
119
+
120
+ def test_reopening_should_not_truncate_the_file
121
+ log = File.join(@tmpdir, 'truncate.log')
122
+ appender = Logging.appenders.file(NAME, filename: log, truncate: true)
123
+
124
+ appender << "This will be the first line\n"
125
+ appender << "This will be the second line\n"
126
+ appender << "This will be the third line\n"
127
+ appender.reopen
118
128
 
119
- cleanup
129
+ File.open(log, 'r') do |file|
130
+ assert_equal "This will be the first line\n", file.readline
131
+ assert_equal "This will be the second line\n", file.readline
132
+ assert_equal "This will be the third line\n", file.readline
133
+ assert_raise(EOFError) {file.readline}
120
134
  end
135
+
136
+ cleanup
121
137
  end
122
138
 
123
139
  private
@@ -127,7 +143,6 @@ module TestAppenders
127
143
  Logging.appenders[NAME] = nil
128
144
  end
129
145
  end
130
-
131
146
  end # TestFile
132
147
 
133
148
  end # TestAppenders
@@ -13,9 +13,9 @@ module TestAppenders
13
13
  super
14
14
  Logging.init
15
15
 
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)
16
+ @fn = File.expand_path('test.log', @tmpdir)
17
+ @fn_fmt = File.expand_path('test.%d.log', @tmpdir)
18
+ @glob = File.expand_path('*.log', @tmpdir)
19
19
  end
20
20
 
21
21
  def test_factory_method_validates_input
@@ -93,8 +93,8 @@ module TestAppenders
93
93
  end
94
94
 
95
95
  def test_age
96
- d_glob = File.join(TMP, 'test.*.log')
97
- dt_glob = File.join(TMP, 'test.*-*.log')
96
+ d_glob = File.join(@tmpdir, 'test.*.log')
97
+ dt_glob = File.join(@tmpdir, 'test.*-*.log')
98
98
  age_fn = @fn + '.age'
99
99
 
100
100
  assert_equal [], Dir.glob(@glob)
@@ -205,7 +205,7 @@ module TestAppenders
205
205
 
206
206
  begin
207
207
  pwd = Dir.pwd
208
- Dir.chdir TMP
208
+ Dir.chdir @tmpdir
209
209
 
210
210
  ap << 'X' * 100; ap.flush
211
211
  assert_equal 1, Dir.glob(@glob).length
@@ -249,9 +249,9 @@ module TestAppenders
249
249
  end
250
250
 
251
251
  def test_custom_numberd_filename
252
- fn = File.expand_path('test.log{{.%d}}', TMP)
253
- filename = File.expand_path('test.log', TMP)
254
- glob = File.expand_path('test.log.*', TMP)
252
+ fn = File.expand_path('test.log{{.%d}}', @tmpdir)
253
+ filename = File.expand_path('test.log', @tmpdir)
254
+ glob = File.expand_path('test.log.*', @tmpdir)
255
255
 
256
256
  assert_equal [], Dir.glob(glob)
257
257
  ap = Logging.appenders.rolling_file(NAME, :filename => fn, :size => 100, :keep => 2)
@@ -285,10 +285,10 @@ module TestAppenders
285
285
  end
286
286
 
287
287
  def test_custom_timestamp_filename
288
- fn = File.expand_path('test{{.%S:%M}}.log', TMP)
289
- filename = File.expand_path('test.log', TMP)
288
+ fn = File.expand_path('test{{.%S:%M}}.log', @tmpdir)
289
+ filename = File.expand_path('test.log', @tmpdir)
290
290
  age_file = filename + '.age'
291
- glob = File.expand_path('test.*.log', TMP)
291
+ glob = File.expand_path('test.*.log', @tmpdir)
292
292
 
293
293
  assert_equal [], Dir.glob(glob)
294
294
  ap = Logging.appenders.rolling_file(NAME, :filename => fn, :age => 1, :keep => 2)
@@ -78,7 +78,7 @@ module TestLayouts
78
78
  'log message', false)
79
79
  event.file = 'test_file.rb'
80
80
  event.line = 123
81
- event.method = 'method_name'
81
+ event.method_name = 'method_name'
82
82
 
83
83
  @layout.items = %w[logger]
84
84
  assert_equal %Q[{"logger":"TestLogger"}\n], @layout.format(event)
@@ -19,7 +19,7 @@ module TestLogging
19
19
  end
20
20
 
21
21
  layout = Logging.layouts.basic({})
22
- log = layout.format_obj(e)
22
+ log = layout.format_obj(err)
23
23
  assert_not_nil log.index('<StandardError> root exception')
24
24
 
25
25
  if err.respond_to?(:cause)
@@ -45,7 +45,7 @@ module TestLogging
45
45
  end
46
46
 
47
47
  layout = Logging.layouts.basic(cause_depth: 1)
48
- log = layout.format_obj(e)
48
+ log = layout.format_obj(err)
49
49
  assert_not_nil log.index('<StandardError> root exception')
50
50
 
51
51
  if err.respond_to?(:cause)
@@ -68,12 +68,12 @@ module TestLogging
68
68
  end
69
69
 
70
70
  layout = Logging.layouts.parseable.new
71
- log = layout.format_obj(e)
71
+ log = layout.format_obj(err)
72
72
  assert_equal 'StandardError', log[:class]
73
73
  assert_equal 'root exception', log[:message]
74
74
  assert log[:backtrace].size > 0
75
75
 
76
- if e.respond_to?(:cause)
76
+ if err.respond_to?(:cause)
77
77
  assert_not_nil log[:cause]
78
78
 
79
79
  log = log[:cause]
@@ -101,13 +101,13 @@ module TestLogging
101
101
  end
102
102
 
103
103
  layout = Logging.layouts.parseable.new(cause_depth: 1)
104
- log = layout.format_obj(e)
104
+ log = layout.format_obj(err)
105
105
 
106
106
  assert_equal 'StandardError', log[:class]
107
107
  assert_equal 'root exception', log[:message]
108
108
  assert log[:backtrace].size > 0
109
109
 
110
- if e.respond_to?(:cause)
110
+ if err.respond_to?(:cause)
111
111
  assert_not_nil log[:cause]
112
112
 
113
113
  log = log[:cause]
@@ -105,7 +105,7 @@ module TestLayouts
105
105
  'log message', false)
106
106
  event.file = 'test_file.rb'
107
107
  event.line = '123'
108
- event.method = 'method_name'
108
+ event.method_name = 'method_name'
109
109
 
110
110
  @layout.pattern = '%c'
111
111
  assert_equal 'TestLogger', @layout.format(event)
@@ -68,7 +68,7 @@ module TestLayouts
68
68
  'log message', false)
69
69
  event.file = 'test_file.rb'
70
70
  event.line = 123
71
- event.method = 'method_name'
71
+ event.method_name = 'method_name'
72
72
 
73
73
  @layout.items = %w[logger]
74
74
  assert_match %r/\A--- ?\nlogger: TestLogger\n/, @layout.format(event)
@@ -5,6 +5,12 @@ LOGGING_TEST_SETUP = true
5
5
 
6
6
  require "rubygems"
7
7
  require "test/unit"
8
+ require "tmpdir"
9
+
10
+ LOGGING_TEST_TMPDIR = Dir.mktmpdir("logging")
11
+ Test::Unit.at_exit do
12
+ FileUtils.remove_entry(LOGGING_TEST_TMPDIR)
13
+ end
8
14
 
9
15
  if Test::Unit::TestCase.respond_to? :test_order=
10
16
  Test::Unit::TestCase.test_order = :random
@@ -15,18 +21,16 @@ require File.expand_path("../../lib/logging", __FILE__)
15
21
  module TestLogging
16
22
  module LoggingTestCase
17
23
 
18
- TMP = 'tmp'
19
-
20
24
  def setup
21
25
  super
22
26
  Logging.reset
23
- FileUtils.rm_rf TMP
24
- FileUtils.mkdir TMP
27
+ @tmpdir = LOGGING_TEST_TMPDIR
28
+ FileUtils.rm_rf(Dir.glob(File.join(@tmpdir, "*")))
25
29
  end
26
30
 
27
31
  def teardown
28
32
  super
29
- FileUtils.rm_rf TMP
33
+ FileUtils.rm_rf(Dir.glob(File.join(@tmpdir, "*")))
30
34
  end
31
35
  end
32
36
  end
@@ -68,12 +68,12 @@ module TestLogging
68
68
  assert_equal 'MyLogger', @event.logger
69
69
  end
70
70
 
71
- def test_method
71
+ def test_method_name
72
72
  assert_equal '', @event.file
73
73
 
74
74
  @logger.caller_tracing = true
75
75
  @logger.debug 'debug message'
76
- assert_equal 'test_method', @appender.event.method
76
+ assert_equal 'test_method_name', @appender.event.method_name
77
77
  end
78
78
 
79
79
  end # class TestLogEvent
@@ -11,8 +11,8 @@ module TestLogging
11
11
  @levels = ::Logging::LEVELS
12
12
  @lnames = ::Logging::LNAMES
13
13
 
14
- @fn = File.join(TMP, 'test.log')
15
- @glob = File.join(TMP, '*.log')
14
+ @fn = File.join(@tmpdir, 'test.log')
15
+ @glob = File.join(@tmpdir, '*.log')
16
16
  end
17
17
 
18
18
  def test_backtrace
@@ -253,6 +253,31 @@ module TestLogging
253
253
  assert_match %r/\d+\.\d+\.\d+/, ::Logging.version
254
254
  end
255
255
 
256
- end # class TestLogging
257
- end # module TestLogging
256
+ class Failer
257
+ class WriteError < StandardError ; end
258
+ def self.write(*args)
259
+ raise WriteError.new("Oh noooooo")
260
+ end
261
+ end
258
262
 
263
+ def test_error_handling
264
+ logger = ::Logging.logger Failer, 2, 100
265
+ logger.appenders.first.level = :debug
266
+
267
+ # No errors are raised by default
268
+ logger.fatal 'this is a debug message'
269
+ # Always reset the level; we disable appenders that raise by setting them
270
+ # to :off
271
+ logger.appenders.first.level = :debug
272
+
273
+ begin
274
+ Logging.raise_errors = true
275
+ assert_raises Failer::WriteError do
276
+ logger.fatal 'this fails because the file descriptor is closed'
277
+ end
278
+ ensure
279
+ Logging.raise_errors = false
280
+ end
281
+ end
282
+ end
283
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Pease
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-11 00:00:00.000000000 Z
11
+ date: 2020-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: little-plugger
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.10'
33
+ version: '1.14'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.10'
40
+ version: '1.14'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: test-unit
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.1'
47
+ version: '3.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.1'
54
+ version: '3.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bones-git
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -179,7 +179,7 @@ files:
179
179
  homepage: http://rubygems.org/gems/logging
180
180
  licenses: []
181
181
  metadata: {}
182
- post_install_message:
182
+ post_install_message:
183
183
  rdoc_options:
184
184
  - "--main"
185
185
  - README.md
@@ -196,9 +196,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  - !ruby/object:Gem::Version
197
197
  version: '0'
198
198
  requirements: []
199
- rubyforge_project: logging
200
- rubygems_version: 2.6.11
201
- signing_key:
199
+ rubygems_version: 3.0.1
200
+ signing_key:
202
201
  specification_version: 4
203
202
  summary: A flexible and extendable logging library for Ruby
204
203
  test_files: