logger 1.2.7.1 → 1.2.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/logger.rb +24 -15
  3. data/test/logger/test_logger.rb +33 -10
  4. metadata +7 -10
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fca3ed305eb759ed28a0ea917d653feee81fc4d399a53a44e6649d8e8389defb
4
+ data.tar.gz: 90cef9d07cb58cb5049c1a869ae56ec609e0dfd1befcac6053b97602e11ee609
5
+ SHA512:
6
+ metadata.gz: c2c96afb68a6e3a22e53673119f673bd6490d6d1c5c184da06677633648c0e86ce6c7eaacbb4dca55c4d3c800ea8d7708c55235a854987c98ed3f20feee185f9
7
+ data.tar.gz: c5e39c441722c99cd6fee091939303d22448a329543699b1deac011d3500f3cf939987ff6c4c64db1cff526a746e1e6050f9af801f057f3aca5181ea734599fa
@@ -1,7 +1,6 @@
1
1
  # logger.rb - simple logging utility
2
- # Copyright (C) 2000-2003, 2005, 2008 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
2
+ # Copyright (C) 2000-2003, 2005, 2008, 2011 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
3
3
  #
4
- # Author:: NAKAMURA, Hiroshi <nakahiro@sarion.co.jp>
5
4
  # Documentation:: NAKAMURA, Hiroshi and Gavin Sinclair
6
5
  # License::
7
6
  # You can redistribute it and/or modify it under the same terms of Ruby's
@@ -41,6 +40,21 @@ require 'monitor'
41
40
  # want to know about the program's internal state, and would set them to
42
41
  # +DEBUG+.
43
42
  #
43
+ # **Note**: Logger does not escape or sanitize any messages passed to it.
44
+ # Developers should be aware of when potentially malicious data (user-input)
45
+ # is passed to Logger, and manually escape the untrusted data:
46
+ #
47
+ # logger.info("User-input: #{input.dump}")
48
+ # logger.info("User-input: %p" % input)
49
+ #
50
+ # You can use Logger#formatter= for escaping all data.
51
+ #
52
+ # original_formatter = Logger::Formatter.new
53
+ # logger.formatter = proc { |severity, datetime, progname, msg|
54
+ # original_formatter.call(severity, datetime, progname, msg.dump)
55
+ # }
56
+ # logger.info(input)
57
+ #
44
58
  # === Example
45
59
  #
46
60
  # A simple example demonstrates the above explanation:
@@ -175,15 +189,8 @@ require 'monitor'
175
189
 
176
190
 
177
191
  class Logger
178
- VERSION = "1.2.7.1"
179
- id, name, rev = %w$Id$
180
- if name
181
- name = name.chomp(",v")
182
- else
183
- name = File.basename(__FILE__)
184
- end
185
- rev ||= "v#{VERSION}"
186
- ProgName = "#{name}/#{rev}"
192
+ VERSION = "1.2.8.1"
193
+ ProgName = "#{File.basename(__FILE__)}/#{VERSION}"
187
194
 
188
195
  class Error < RuntimeError; end
189
196
  class ShiftingError < Error; end # not used after 1.2.7. just for compat.
@@ -210,6 +217,8 @@ class Logger
210
217
  @default_formatter.datetime_format = datetime_format
211
218
  end
212
219
 
220
+ # Returns the date format (string passed to +strftime+) being used (it's set
221
+ # using datetime_format=)
213
222
  def datetime_format
214
223
  @default_formatter.datetime_format
215
224
  end
@@ -290,8 +299,8 @@ class Logger
290
299
  # +message+::
291
300
  # The log message. A String or Exception.
292
301
  # +progname+::
293
- # Program name string. Can be omitted. Treated as a message if no +message+ and
294
- # +block+ are given.
302
+ # Program name string. Can be omitted. Treated as a message if no
303
+ # +message+ and +block+ are given.
295
304
  # +block+::
296
305
  # Can be omitted. Called to get a message string if +message+ is nil.
297
306
  #
@@ -530,7 +539,7 @@ private
530
539
  @mutex.synchronize do
531
540
  @dev.close rescue nil
532
541
  end
533
- rescue Exception => ignored
542
+ rescue Exception
534
543
  @dev.close rescue nil
535
544
  end
536
545
  end
@@ -593,7 +602,7 @@ private
593
602
  if FileTest.exist?(age_file)
594
603
  # try to avoid filename crash caused by Timestamp change.
595
604
  idx = 0
596
- # .99 can be overriden; avoid too much file search with 'loop do'
605
+ # .99 can be overridden; avoid too much file search with 'loop do'
597
606
  while idx < 100
598
607
  idx += 1
599
608
  age_file = "#{@filename}.#{postfix}.#{idx}"
@@ -311,10 +311,14 @@ class TestLogDevice < Test::Unit::TestCase
311
311
  end
312
312
  # create logfile whitch is already exist.
313
313
  logdev = d(@filename)
314
- logdev.write('world')
315
- logfile = File.read(@filename)
316
- assert_equal(2, logfile.split(/\n/).size)
317
- assert_match(/^helloworld$/, logfile)
314
+ begin
315
+ logdev.write('world')
316
+ logfile = File.read(@filename)
317
+ assert_equal(2, logfile.split(/\n/).size)
318
+ assert_match(/^helloworld$/, logfile)
319
+ ensure
320
+ logdev.close
321
+ end
318
322
  end
319
323
 
320
324
  def test_write
@@ -328,13 +332,19 @@ class TestLogDevice < Test::Unit::TestCase
328
332
  assert_equal("msg2\n\n", msg)
329
333
  #
330
334
  logdev = d(LogExcnRaiser.new)
335
+ class << (stderr = '')
336
+ alias write <<
337
+ end
338
+ $stderr, stderr = stderr, $stderr
331
339
  begin
332
340
  assert_nothing_raised do
333
341
  logdev.write('hello')
334
342
  end
335
343
  ensure
336
344
  logdev.close
345
+ $stderr, stderr = stderr, $stderr
337
346
  end
347
+ assert_equal "log writing failed. disk is full\n", stderr
338
348
  end
339
349
 
340
350
  def test_close
@@ -458,6 +468,7 @@ class TestLogDevice < Test::Unit::TestCase
458
468
  assert(File.exist?(filename2))
459
469
  assert(File.exist?(filename3))
460
470
  ensure
471
+ logger.close if logger
461
472
  [filename1, filename2, filename3].each do |filename|
462
473
  File.unlink(filename) if File.exist?(filename)
463
474
  end
@@ -485,20 +496,32 @@ class TestLoggerApplication < Test::Unit::TestCase
485
496
 
486
497
  def test_start
487
498
  @app.set_log(@filename)
488
- @app.level = Logger::UNKNOWN
489
- @app.start # logs FATAL log
490
- assert_equal(1, File.read(@filename).split(/\n/).size)
499
+ begin
500
+ @app.level = Logger::UNKNOWN
501
+ @app.start # logs FATAL log
502
+ assert_equal(1, File.read(@filename).split(/\n/).size)
503
+ ensure
504
+ @app.logger.close
505
+ end
491
506
  end
492
507
 
493
508
  def test_logger
494
509
  @app.level = Logger::WARN
495
510
  @app.set_log(@filename)
496
- assert_equal(Logger::WARN, @app.logger.level)
511
+ begin
512
+ assert_equal(Logger::WARN, @app.logger.level)
513
+ ensure
514
+ @app.logger.close
515
+ end
497
516
  @app.logger = logger = Logger.new(STDOUT)
498
517
  assert_equal(logger, @app.logger)
499
518
  assert_equal(Logger::WARN, @app.logger.level)
500
519
  @app.log = @filename
501
- assert(logger != @app.logger)
502
- assert_equal(Logger::WARN, @app.logger.level)
520
+ begin
521
+ assert(logger != @app.logger)
522
+ assert_equal(Logger::WARN, @app.logger.level)
523
+ ensure
524
+ @app.logger.close
525
+ end
503
526
  end
504
527
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7.1
5
- prerelease:
4
+ version: 1.2.8.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - NAKAMURA, Hiroshi
@@ -10,7 +9,7 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2019-01-11 00:00:00.000000000 Z
12
+ date: 2019-01-19 00:00:00.000000000 Z
14
13
  dependencies: []
15
14
  description: Provides a simple logging utility for outputting messages.
16
15
  email:
@@ -25,26 +24,24 @@ files:
25
24
  homepage: https://github.com/ruby/logger
26
25
  licenses:
27
26
  - BSD-2-Clause
27
+ metadata: {}
28
28
  post_install_message:
29
29
  rdoc_options: []
30
30
  require_paths:
31
31
  - lib
32
32
  required_ruby_version: !ruby/object:Gem::Requirement
33
- none: false
34
33
  requirements:
35
- - - ! '>='
34
+ - - ">="
36
35
  - !ruby/object:Gem::Version
37
36
  version: '0'
38
37
  required_rubygems_version: !ruby/object:Gem::Requirement
39
- none: false
40
38
  requirements:
41
- - - ! '>='
39
+ - - ">="
42
40
  - !ruby/object:Gem::Version
43
41
  version: '0'
44
42
  requirements: []
45
- rubyforge_project:
46
- rubygems_version: 1.8.23.2
43
+ rubygems_version: 3.0.2
47
44
  signing_key:
48
- specification_version: 3
45
+ specification_version: 4
49
46
  summary: Provides a simple logging utility for outputting messages.
50
47
  test_files: []