logger 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25185d093ab5e02f9933ce7d395e5929f1ad6f345301fbbbded9e720f67c16e4
4
- data.tar.gz: 44d81cc02f511f27d70f3ece4bf99670e9b292a625b0984a47dc128c836385e9
3
+ metadata.gz: c6fa7c02974cf7c275bfa19e6225f8b06bdbc76d49f78e6bf75e351dfb14c1e3
4
+ data.tar.gz: d299b1c26a5389316c89a7899359f5d8d1570dae24428bce6c43d9832adc7dc2
5
5
  SHA512:
6
- metadata.gz: 7055c80ccdc88976a5616b6a648ba877c6c2fba8a6d6c575ed88dda70a537ba2aa698574128b8824f68521715762cb38a7f2c1847713a6ba5ff7941241d99e24
7
- data.tar.gz: 0c7d1bdf93857052c4fbbf64536445d2b2eefddb33b527d18bd2a6b638b0771b92b846b669d57b7500c280bd8fe4ae836ecad5e8b92517a0d2d4aaac66784182
6
+ metadata.gz: 9b19a5196c89b0c184c5c2ab4a77d5085d26ec6f04c272b7bbd0085beaeaf7d758e9cb0c728c486e07f4498209e70327420ff66f218b4f6baec7d59fe7ec0c44
7
+ data.tar.gz: 1fc54467c631ea277b044c9d2b48895f3d2ed684eec2725f3aa1e475c551e1cfb6420fe9540a5eddf0e597794f74ee8c669c506faad44af5ddb8075cb7c8826e
@@ -11,9 +11,10 @@ class Logger
11
11
  attr_reader :filename
12
12
  include MonitorMixin
13
13
 
14
- def initialize(log = nil, shift_age: nil, shift_size: nil, shift_period_suffix: nil, binmode: false)
14
+ def initialize(log = nil, shift_age: nil, shift_size: nil, shift_period_suffix: nil, binmode: false, reraise_write_errors: [])
15
15
  @dev = @filename = @shift_age = @shift_size = @shift_period_suffix = nil
16
16
  @binmode = binmode
17
+ @reraise_write_errors = reraise_write_errors
17
18
  mon_initialize
18
19
  set_dev(log)
19
20
  if @filename
@@ -34,16 +35,22 @@ class Logger
34
35
  if @shift_age and @dev.respond_to?(:stat)
35
36
  begin
36
37
  check_shift_log
38
+ rescue *@reraise_write_errors
39
+ raise
37
40
  rescue
38
41
  warn("log shifting failed. #{$!}")
39
42
  end
40
43
  end
41
44
  begin
42
45
  @dev.write(message)
46
+ rescue *@reraise_write_errors
47
+ raise
43
48
  rescue
44
49
  warn("log writing failed. #{$!}")
45
50
  end
46
51
  end
52
+ rescue *@reraise_write_errors
53
+ raise
47
54
  rescue Exception => ignored
48
55
  warn("log writing failed. #{ignored}")
49
56
  end
data/lib/logger/period.rb CHANGED
@@ -8,14 +8,14 @@ class Logger
8
8
 
9
9
  def next_rotate_time(now, shift_age)
10
10
  case shift_age
11
- when 'daily'
11
+ when 'daily', :daily
12
12
  t = Time.mktime(now.year, now.month, now.mday) + SiD
13
- when 'weekly'
13
+ when 'weekly', :weekly
14
14
  t = Time.mktime(now.year, now.month, now.mday) + SiD * (7 - now.wday)
15
- when 'monthly'
15
+ when 'monthly', :monthly
16
16
  t = Time.mktime(now.year, now.month, 1) + SiD * 32
17
17
  return Time.mktime(t.year, t.month, 1)
18
- when 'now', 'everytime'
18
+ when 'now', 'everytime', :now, :everytime
19
19
  return now
20
20
  else
21
21
  raise ArgumentError, "invalid :shift_age #{shift_age.inspect}, should be daily, weekly, monthly, or everytime"
@@ -30,13 +30,13 @@ class Logger
30
30
 
31
31
  def previous_period_end(now, shift_age)
32
32
  case shift_age
33
- when 'daily'
33
+ when 'daily', :daily
34
34
  t = Time.mktime(now.year, now.month, now.mday) - SiD / 2
35
- when 'weekly'
35
+ when 'weekly', :weekly
36
36
  t = Time.mktime(now.year, now.month, now.mday) - (SiD * now.wday + SiD / 2)
37
- when 'monthly'
37
+ when 'monthly', :monthly
38
38
  t = Time.mktime(now.year, now.month, 1) - SiD / 2
39
- when 'now', 'everytime'
39
+ when 'now', 'everytime', :now, :everytime
40
40
  return now
41
41
  else
42
42
  raise ArgumentError, "invalid :shift_age #{shift_age.inspect}, should be daily, weekly, monthly, or everytime"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Logger
4
- VERSION = "1.6.0"
4
+ VERSION = "1.6.1"
5
5
  end
data/lib/logger.rb CHANGED
@@ -381,7 +381,7 @@ class Logger
381
381
 
382
382
  # Logging severity threshold (e.g. <tt>Logger::INFO</tt>).
383
383
  def level
384
- @level_override[Fiber.current] || @level
384
+ level_override[Fiber.current] || @level
385
385
  end
386
386
 
387
387
  # Sets the log level; returns +severity+.
@@ -406,14 +406,14 @@ class Logger
406
406
  # logger.debug { "Hello" }
407
407
  # end
408
408
  def with_level(severity)
409
- prev, @level_override[Fiber.current] = level, Severity.coerce(severity)
409
+ prev, level_override[Fiber.current] = level, Severity.coerce(severity)
410
410
  begin
411
411
  yield
412
412
  ensure
413
413
  if prev
414
- @level_override[Fiber.current] = prev
414
+ level_override[Fiber.current] = prev
415
415
  else
416
- @level_override.delete(Fiber.current)
416
+ level_override.delete(Fiber.current)
417
417
  end
418
418
  end
419
419
  end
@@ -574,10 +574,14 @@ class Logger
574
574
  # - +shift_period_suffix+: sets the format for the filename suffix
575
575
  # for periodic log file rotation; default is <tt>'%Y%m%d'</tt>.
576
576
  # See {Periodic Rotation}[rdoc-ref:Logger@Periodic+Rotation].
577
+ # - +reraise_write_errors+: An array of exception classes, which will
578
+ # be reraised if there is an error when writing to the log device.
579
+ # The default is to swallow all exceptions raised.
577
580
  #
578
581
  def initialize(logdev, shift_age = 0, shift_size = 1048576, level: DEBUG,
579
582
  progname: nil, formatter: nil, datetime_format: nil,
580
- binmode: false, shift_period_suffix: '%Y%m%d')
583
+ binmode: false, shift_period_suffix: '%Y%m%d',
584
+ reraise_write_errors: [])
581
585
  self.level = level
582
586
  self.progname = progname
583
587
  @default_formatter = Formatter.new
@@ -589,7 +593,8 @@ class Logger
589
593
  @logdev = LogDevice.new(logdev, shift_age: shift_age,
590
594
  shift_size: shift_size,
591
595
  shift_period_suffix: shift_period_suffix,
592
- binmode: binmode)
596
+ binmode: binmode,
597
+ reraise_write_errors: reraise_write_errors)
593
598
  end
594
599
  end
595
600
 
@@ -741,6 +746,11 @@ private
741
746
  SEV_LABEL[severity] || 'ANY'
742
747
  end
743
748
 
749
+ # Guarantee the existence of this ivar even when subclasses don't call the superclass constructor.
750
+ def level_override
751
+ @level_override ||= {}
752
+ end
753
+
744
754
  def format_message(severity, datetime, progname, msg)
745
755
  (@formatter || @default_formatter).call(severity, datetime, progname, msg)
746
756
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  - SHIBATA Hiroshi
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2023-11-07 00:00:00.000000000 Z
11
+ date: 2024-09-02 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Provides a simple logging utility for outputting messages.
15
14
  email:
@@ -32,7 +31,6 @@ licenses:
32
31
  - Ruby
33
32
  - BSD-2-Clause
34
33
  metadata: {}
35
- post_install_message:
36
34
  rdoc_options: []
37
35
  require_paths:
38
36
  - lib
@@ -47,8 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
45
  - !ruby/object:Gem::Version
48
46
  version: '0'
49
47
  requirements: []
50
- rubygems_version: 3.5.0.dev
51
- signing_key:
48
+ rubygems_version: 3.6.0.dev
52
49
  specification_version: 4
53
50
  summary: Provides a simple logging utility for outputting messages.
54
51
  test_files: []