console 1.17.2 → 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: 689cedcf29ff2b68070c411deb10790350808468c1ad3dde6857522e9d87cd0c
4
- data.tar.gz: afb2b73337d57ffb59b41281f81736b30ba646a58925663fbb7f8bf356d65dd6
3
+ metadata.gz: b5e54a0a87d6c2ad440476163691fcc67016d8cdabd95f218f0e55db0a311ffd
4
+ data.tar.gz: a1cc36ed4d66731525458abebac6ba9081e68c17524bc32a0125291684b8107b
5
5
  SHA512:
6
- metadata.gz: 86d91efd799280a3e88fd0199ace0b305789f02ba55a658aa3c6baf2d1b31969658d0f946463d0220c3e2f032f62b62c3a6226753db49935d6a3dc7983cc3717
7
- data.tar.gz: bba2266b438742f21cf0819db3e948509d354f4c4477a032218b529f2efd0d12577956eb46adb364365f80cc4079587d4d615d217b124e0c230c9543b642261a
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,13 +37,17 @@ 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
  }
44
43
 
45
- if subject
44
+ # We want to log just a brief subject:
45
+ if subject.is_a?(String)
46
46
  record[:subject] = subject
47
+ elsif subject.is_a?(Module)
48
+ record[:subject] = subject.name
49
+ else
50
+ record[:subject] = subject.class.name
47
51
  end
48
52
 
49
53
  if annotation = Fiber.current.annotation
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2019-2022, by Samuel Williams.
5
5
 
6
6
  module Console
7
- VERSION = "1.17.2"
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.2
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-06-06 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
@@ -213,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
214
  - !ruby/object:Gem::Version
214
215
  version: '0'
215
216
  requirements: []
216
- rubygems_version: 3.4.7
217
+ rubygems_version: 3.4.10
217
218
  signing_key:
218
219
  specification_version: 4
219
220
  summary: Beautiful logging for Ruby.
metadata.gz.sig CHANGED
Binary file