console 1.17.3 → 1.18.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: e84e89c5147fddf5d7dcbac7609431adce37ee40b2e6e4ac28c9275054c4d1e1
4
- data.tar.gz: 3a919ba4deb380f97009df1c8f3bee617624359415044e457f21bfb6b0100627
3
+ metadata.gz: b5e54a0a87d6c2ad440476163691fcc67016d8cdabd95f218f0e55db0a311ffd
4
+ data.tar.gz: a1cc36ed4d66731525458abebac6ba9081e68c17524bc32a0125291684b8107b
5
5
  SHA512:
6
- metadata.gz: fe3f04bb8844f111c29aa00f63e0da6025babb8685d21002be06e23d11d60da620f943b5e0f0e75abad4548f8033a3417df5d3ff891e97ba114e0464510d07b1
7
- data.tar.gz: 4617e34bcb9ef30a67d2f787babcc3bfa183ae8af4228bb7092362078841ada2e70227fe7ee7b3b09e4465e0f49a7784b374bcd9a3893781ee6aeb700aaa12d2
6
+ metadata.gz: 864fb845fbdb448f16a7c6b43d024ab5581ad42eb3187efcba046f9feff43f59bdb0164e5fb94fac34bd1387d26742d32395827d9e5d30a158ea8dbc8cd47391
7
+ data.tar.gz: 6af247ea1c0c9df853dfae8de8c651ed487e4ae010d46975586e23a6fc1925cd7a20d27545495cba3e14ea0e8246fc87f88c51acbd226cd10d7ce092338c0efe
checksums.yaml.gz.sig CHANGED
Binary file
@@ -14,12 +14,12 @@ module Console
14
14
  class Filter
15
15
  def self.[] **levels
16
16
  klass = Class.new(self)
17
- min_level, max_level = levels.values.minmax
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, min_level)
22
- const_set(:MAXIMUM_LEVEL, max_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, enabled: nil, **options)
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
- if specific_level = @subjects[subject.class]
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 [Class] The class to enable.
116
+ # @parameter name [Module] The class to enable.
111
117
  def enable(subject, level = self.class::MINIMUM_LEVEL)
112
- unless subject.is_a?(Class)
113
- raise ArgumentError, "Expected a class, got #{subject.inspect}"
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
- unless subject.is_a?(Class)
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
@@ -7,6 +7,7 @@ require_relative 'output/default'
7
7
  require_relative 'output/json'
8
8
  require_relative 'output/text'
9
9
  require_relative 'output/xterm'
10
+ require_relative 'output/null'
10
11
 
11
12
  module Console
12
13
  module Output
@@ -37,7 +37,6 @@ module Console
37
37
  record = {
38
38
  time: Time.now.iso8601,
39
39
  severity: severity,
40
- class: subject.class,
41
40
  oid: subject.object_id,
42
41
  pid: Process.pid,
43
42
  }
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2019-2022, by Samuel Williams.
5
5
 
6
6
  module Console
7
- VERSION = "1.17.3"
7
+ VERSION = "1.18.0"
8
8
  end
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.17.3
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-19 00:00:00.000000000 Z
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