logger 1.5.2 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/logger/formatter.rb +2 -3
- data/lib/logger/log_device.rb +4 -2
- data/lib/logger/severity.rb +19 -0
- data/lib/logger/version.rb +1 -1
- data/lib/logger.rb +22 -20
- data/logger.gemspec +1 -6
- metadata +5 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25185d093ab5e02f9933ce7d395e5929f1ad6f345301fbbbded9e720f67c16e4
|
4
|
+
data.tar.gz: 44d81cc02f511f27d70f3ece4bf99670e9b292a625b0984a47dc128c836385e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7055c80ccdc88976a5616b6a648ba877c6c2fba8a6d6c575ed88dda70a537ba2aa698574128b8824f68521715762cb38a7f2c1847713a6ba5ff7941241d99e24
|
7
|
+
data.tar.gz: 0c7d1bdf93857052c4fbbf64536445d2b2eefddb33b527d18bd2a6b638b0771b92b846b669d57b7500c280bd8fe4ae836ecad5e8b92517a0d2d4aaac66784182
|
data/lib/logger/formatter.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
class Logger
|
4
4
|
# Default formatter for log messages.
|
5
5
|
class Formatter
|
6
|
-
Format = "
|
6
|
+
Format = "%.1s, [%s #%d] %5s -- %s: %s\n"
|
7
7
|
DatetimeFormat = "%Y-%m-%dT%H:%M:%S.%6N"
|
8
8
|
|
9
9
|
attr_accessor :datetime_format
|
@@ -13,8 +13,7 @@ class Logger
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def call(severity, time, progname, msg)
|
16
|
-
Format
|
17
|
-
msg2str(msg)]
|
16
|
+
sprintf(Format, severity, format_datetime(time), Process.pid, severity, progname, msg2str(msg))
|
18
17
|
end
|
19
18
|
|
20
19
|
private
|
data/lib/logger/log_device.rb
CHANGED
@@ -79,8 +79,10 @@ class Logger
|
|
79
79
|
def set_dev(log)
|
80
80
|
if log.respond_to?(:write) and log.respond_to?(:close)
|
81
81
|
@dev = log
|
82
|
-
if log.respond_to?(:path)
|
83
|
-
|
82
|
+
if log.respond_to?(:path) and path = log.path
|
83
|
+
if File.exist?(path)
|
84
|
+
@filename = path
|
85
|
+
end
|
84
86
|
end
|
85
87
|
else
|
86
88
|
@dev = open_logfile(log)
|
data/lib/logger/severity.rb
CHANGED
@@ -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
|
data/lib/logger/version.rb
CHANGED
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
|
-
|
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
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
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
|
-
|
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,10 +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.
|
22
|
-
|
23
|
-
spec.add_development_dependency "bundler", ">= 0"
|
24
|
-
spec.add_development_dependency "rake", ">= 12.3.3"
|
25
|
-
spec.add_development_dependency "test-unit"
|
26
|
-
spec.add_development_dependency "rdoc"
|
21
|
+
spec.required_ruby_version = ">= 2.5.0"
|
27
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.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
@@ -9,64 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
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'
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: rdoc
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '0'
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - ">="
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
12
|
+
date: 2023-11-07 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
70
14
|
description: Provides a simple logging utility for outputting messages.
|
71
15
|
email:
|
72
16
|
- sonots@gmail.com
|
@@ -96,14 +40,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
40
|
requirements:
|
97
41
|
- - ">="
|
98
42
|
- !ruby/object:Gem::Version
|
99
|
-
version: 2.
|
43
|
+
version: 2.5.0
|
100
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
45
|
requirements:
|
102
46
|
- - ">="
|
103
47
|
- !ruby/object:Gem::Version
|
104
48
|
version: '0'
|
105
49
|
requirements: []
|
106
|
-
rubygems_version: 3.
|
50
|
+
rubygems_version: 3.5.0.dev
|
107
51
|
signing_key:
|
108
52
|
specification_version: 4
|
109
53
|
summary: Provides a simple logging utility for outputting messages.
|