console 1.17.4 → 1.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/console/filter.rb +26 -18
- data/lib/console/output/null.rb +17 -0
- data/lib/console/output.rb +1 -0
- data/lib/console/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +3 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5e54a0a87d6c2ad440476163691fcc67016d8cdabd95f218f0e55db0a311ffd
|
4
|
+
data.tar.gz: a1cc36ed4d66731525458abebac6ba9081e68c17524bc32a0125291684b8107b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 864fb845fbdb448f16a7c6b43d024ab5581ad42eb3187efcba046f9feff43f59bdb0164e5fb94fac34bd1387d26742d32395827d9e5d30a158ea8dbc8cd47391
|
7
|
+
data.tar.gz: 6af247ea1c0c9df853dfae8de8c651ed487e4ae010d46975586e23a6fc1925cd7a20d27545495cba3e14ea0e8246fc87f88c51acbd226cd10d7ce092338c0efe
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/console/filter.rb
CHANGED
@@ -14,12 +14,12 @@ module Console
|
|
14
14
|
class Filter
|
15
15
|
def self.[] **levels
|
16
16
|
klass = Class.new(self)
|
17
|
-
|
17
|
+
minimum_level, maximum_level = levels.values.minmax
|
18
18
|
|
19
19
|
klass.instance_exec do
|
20
20
|
const_set(:LEVELS, levels.freeze)
|
21
|
-
const_set(:MINIMUM_LEVEL,
|
22
|
-
const_set(:MAXIMUM_LEVEL,
|
21
|
+
const_set(:MINIMUM_LEVEL, minimum_level)
|
22
|
+
const_set(:MAXIMUM_LEVEL, maximum_level)
|
23
23
|
|
24
24
|
levels.each do |name, level|
|
25
25
|
const_set(name.to_s.upcase, level)
|
@@ -43,7 +43,7 @@ module Console
|
|
43
43
|
return klass
|
44
44
|
end
|
45
45
|
|
46
|
-
def initialize(output, verbose: true, level: self.class::DEFAULT_LEVEL,
|
46
|
+
def initialize(output, verbose: true, level: self.class::DEFAULT_LEVEL, **options)
|
47
47
|
@output = output
|
48
48
|
@verbose = verbose
|
49
49
|
@level = level
|
@@ -51,10 +51,6 @@ module Console
|
|
51
51
|
@subjects = {}
|
52
52
|
|
53
53
|
@options = options
|
54
|
-
|
55
|
-
if enabled
|
56
|
-
enabled.each{|name| enable(name)}
|
57
|
-
end
|
58
54
|
end
|
59
55
|
|
60
56
|
def with(level: @level, verbose: @verbose, **options)
|
@@ -94,10 +90,20 @@ module Console
|
|
94
90
|
@level = self.class::MINIMUM_LEVEL - 1
|
95
91
|
end
|
96
92
|
|
93
|
+
def filter(subject, level)
|
94
|
+
unless subject.is_a?(Module)
|
95
|
+
raise ArgumentError, "Expected a class, got #{subject.inspect}"
|
96
|
+
end
|
97
|
+
|
98
|
+
@subjects[subject] = level
|
99
|
+
end
|
100
|
+
|
97
101
|
# You can enable and disable logging for classes. This function checks if logging for a given subject is enabled.
|
98
102
|
# @param subject [Object] the subject to check.
|
99
103
|
def enabled?(subject, level = self.class::MINIMUM_LEVEL)
|
100
|
-
|
104
|
+
subject = subject.class unless subject.is_a?(Module)
|
105
|
+
|
106
|
+
if specific_level = @subjects[subject]
|
101
107
|
return level >= specific_level
|
102
108
|
end
|
103
109
|
|
@@ -107,19 +113,21 @@ module Console
|
|
107
113
|
end
|
108
114
|
|
109
115
|
# Enable specific log level for the given class.
|
110
|
-
# @parameter name [
|
116
|
+
# @parameter name [Module] The class to enable.
|
111
117
|
def enable(subject, level = self.class::MINIMUM_LEVEL)
|
112
|
-
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
@subjects[subject] = level
|
118
|
+
# Set the filter level of logging for a given subject which passes all log messages:
|
119
|
+
filter(subject, level)
|
117
120
|
end
|
118
121
|
|
119
|
-
# Disable specific logging for the specific class.
|
120
|
-
# @parameter name [Class] The class to disable.
|
121
122
|
def disable(subject)
|
122
|
-
|
123
|
+
# Set the filter level of the logging for a given subject which filters all log messages:
|
124
|
+
filter(subject, self.class::MAXIMUM_LEVEL + 1)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Clear any specific filters for the given class.
|
128
|
+
# @parameter name [Module] The class to disable.
|
129
|
+
def clear(subject)
|
130
|
+
unless subject.is_a?(Module)
|
123
131
|
raise ArgumentError, "Expected a class, got #{subject.inspect}"
|
124
132
|
end
|
125
133
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2023, by Samuel Williams.
|
5
|
+
|
6
|
+
module Console
|
7
|
+
module Output
|
8
|
+
class Null
|
9
|
+
def initialize(...)
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(...)
|
13
|
+
# Do nothing.
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/console/output.rb
CHANGED
data/lib/console/version.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -43,7 +43,7 @@ cert_chain:
|
|
43
43
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
44
44
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
45
45
|
-----END CERTIFICATE-----
|
46
|
-
date: 2023-07-
|
46
|
+
date: 2023-07-21 00:00:00.000000000 Z
|
47
47
|
dependencies:
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: fiber-local
|
@@ -179,6 +179,7 @@ files:
|
|
179
179
|
- lib/console/output.rb
|
180
180
|
- lib/console/output/default.rb
|
181
181
|
- lib/console/output/json.rb
|
182
|
+
- lib/console/output/null.rb
|
182
183
|
- lib/console/output/sensitive.rb
|
183
184
|
- lib/console/output/split.rb
|
184
185
|
- lib/console/output/text.rb
|
metadata.gz.sig
CHANGED
Binary file
|