logger 1.5.3 → 1.6.0

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: 299d68259bad0228e1e6519f73ddbef94902a8e04f230ad8bbc38f1cb7c45dee
4
- data.tar.gz: 9178b4b52d2e025fefb9dcadebd94ff6a95392d5d381b949f8d2cb454d456bab
3
+ metadata.gz: 25185d093ab5e02f9933ce7d395e5929f1ad6f345301fbbbded9e720f67c16e4
4
+ data.tar.gz: 44d81cc02f511f27d70f3ece4bf99670e9b292a625b0984a47dc128c836385e9
5
5
  SHA512:
6
- metadata.gz: 1ee506486c7af0e574c4c4c58b28ca10c2d0d4a0493d0b405e43af96e93bb0c397dee7b128d0d89e7793724b6f0cb186c8e2d33aa2ff8cfc6e847e830e6c0127
7
- data.tar.gz: 70c4a17f55e4eb5d2323ef5218151de9638a70b8690f6a40180b051554a17bd58b4a09521bbc8ca6a55b60afc9215d51b1c37873c0883e5ba3f42d89e4965a36
6
+ metadata.gz: 7055c80ccdc88976a5616b6a648ba877c6c2fba8a6d6c575ed88dda70a537ba2aa698574128b8824f68521715762cb38a7f2c1847713a6ba5ff7941241d99e24
7
+ data.tar.gz: 0c7d1bdf93857052c4fbbf64536445d2b2eefddb33b527d18bd2a6b638b0771b92b846b669d57b7500c280bd8fe4ae836ecad5e8b92517a0d2d4aaac66784182
@@ -15,5 +15,24 @@ class Logger
15
15
  FATAL = 4
16
16
  # An unknown message that should always be logged.
17
17
  UNKNOWN = 5
18
+
19
+ LEVELS = {
20
+ "debug" => DEBUG,
21
+ "info" => INFO,
22
+ "warn" => WARN,
23
+ "error" => ERROR,
24
+ "fatal" => FATAL,
25
+ "unknown" => UNKNOWN,
26
+ }
27
+ private_constant :LEVELS
28
+
29
+ def self.coerce(severity)
30
+ if severity.is_a?(Integer)
31
+ severity
32
+ else
33
+ key = severity.to_s.downcase
34
+ LEVELS[key] || raise(ArgumentError, "invalid log level: #{severity}")
35
+ end
36
+ end
18
37
  end
19
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Logger
4
- VERSION = "1.5.3"
4
+ VERSION = "1.6.0"
5
5
  end
data/lib/logger.rb CHANGED
@@ -10,6 +10,7 @@
10
10
  #
11
11
  # A simple system for logging messages. See Logger for more documentation.
12
12
 
13
+ require 'fiber'
13
14
  require 'monitor'
14
15
  require 'rbconfig'
15
16
 
@@ -264,8 +265,7 @@ require_relative 'logger/errors'
264
265
  # logger.error! # => 3
265
266
  # logger.fatal! # => 4
266
267
  #
267
- # You can retrieve the log level with method
268
- # {level}[Logger.html#attribute-i-level]:
268
+ # You can retrieve the log level with method #level.
269
269
  #
270
270
  # logger.level = Logger::ERROR
271
271
  # logger.level # => 3
@@ -380,7 +380,9 @@ class Logger
380
380
  include Severity
381
381
 
382
382
  # Logging severity threshold (e.g. <tt>Logger::INFO</tt>).
383
- attr_reader :level
383
+ def level
384
+ @level_override[Fiber.current] || @level
385
+ end
384
386
 
385
387
  # Sets the log level; returns +severity+.
386
388
  # See {Log Level}[rdoc-ref:Logger@Log+Level].
@@ -395,24 +397,23 @@ class Logger
395
397
  # Logger#sev_threshold= is an alias for Logger#level=.
396
398
  #
397
399
  def level=(severity)
398
- if severity.is_a?(Integer)
399
- @level = severity
400
- else
401
- case severity.to_s.downcase
402
- when 'debug'
403
- @level = DEBUG
404
- when 'info'
405
- @level = INFO
406
- when 'warn'
407
- @level = WARN
408
- when 'error'
409
- @level = ERROR
410
- when 'fatal'
411
- @level = FATAL
412
- when 'unknown'
413
- @level = UNKNOWN
400
+ @level = Severity.coerce(severity)
401
+ end
402
+
403
+ # Adjust the log level during the block execution for the current Fiber only
404
+ #
405
+ # logger.with_level(:debug) do
406
+ # logger.debug { "Hello" }
407
+ # end
408
+ def with_level(severity)
409
+ prev, @level_override[Fiber.current] = level, Severity.coerce(severity)
410
+ begin
411
+ yield
412
+ ensure
413
+ if prev
414
+ @level_override[Fiber.current] = prev
414
415
  else
415
- raise ArgumentError, "invalid log level: #{severity}"
416
+ @level_override.delete(Fiber.current)
416
417
  end
417
418
  end
418
419
  end
@@ -583,6 +584,7 @@ class Logger
583
584
  self.datetime_format = datetime_format
584
585
  self.formatter = formatter
585
586
  @logdev = nil
587
+ @level_override = {}
586
588
  if logdev && logdev != File::NULL
587
589
  @logdev = LogDevice.new(logdev, shift_age: shift_age,
588
590
  shift_size: shift_size,
data/logger.gemspec CHANGED
@@ -18,9 +18,5 @@ Gem::Specification.new do |spec|
18
18
  spec.files = Dir.glob("lib/**/*.rb") + ["logger.gemspec"]
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.required_ruby_version = ">= 2.3.0"
22
-
23
- spec.add_development_dependency "bundler", ">= 0"
24
- spec.add_development_dependency "rake", ">= 12.3.3"
25
- spec.add_development_dependency "test-unit"
21
+ spec.required_ruby_version = ">= 2.5.0"
26
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
@@ -9,50 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-12-16 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: bundler
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: '0'
28
- - !ruby/object:Gem::Dependency
29
- name: rake
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: 12.3.3
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: 12.3.3
42
- - !ruby/object:Gem::Dependency
43
- name: test-unit
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: '0'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: '0'
12
+ date: 2023-11-07 00:00:00.000000000 Z
13
+ dependencies: []
56
14
  description: Provides a simple logging utility for outputting messages.
57
15
  email:
58
16
  - sonots@gmail.com
@@ -82,14 +40,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
40
  requirements:
83
41
  - - ">="
84
42
  - !ruby/object:Gem::Version
85
- version: 2.3.0
43
+ version: 2.5.0
86
44
  required_rubygems_version: !ruby/object:Gem::Requirement
87
45
  requirements:
88
46
  - - ">="
89
47
  - !ruby/object:Gem::Version
90
48
  version: '0'
91
49
  requirements: []
92
- rubygems_version: 3.3.26
50
+ rubygems_version: 3.5.0.dev
93
51
  signing_key:
94
52
  specification_version: 4
95
53
  summary: Provides a simple logging utility for outputting messages.