reality-core 1.4.0 → 1.5.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
  SHA1:
3
- metadata.gz: d24305253302c7aa643f825e17153efba609f57d
4
- data.tar.gz: 3a8f9a866751c58b4fae0d1cc1cace8dd97205a2
3
+ metadata.gz: f0001afc36f924a295d6b3461b1cdcd78ac7546a
4
+ data.tar.gz: 739121f92b960be4f5f27f18c0378a23a4727fa5
5
5
  SHA512:
6
- metadata.gz: 9f9cfe5ec01a41b474e6520ce4aa2ec7b360976570f05f8fb362c64675e9c8cf100ed472a2320f626033da1dd02e0390cb08582a0e01295da3bc8378d49dbc95
7
- data.tar.gz: d6f572d5cbfa2e6cdd920b49f691a23b19f16e5874a6023310f221ab68fbef1b2e83a2a3067d79b39f848fa8d1e35f72d8b7e82c1ee27c33103938807c86f702
6
+ metadata.gz: 4a968ddcf90298e09ba2ca6d2d6037e33819ffe73f214f30fbcf3cb9f44debdc1113e71d01aba8e3843da9f0981781200f060009082f924b6f6f384092ce8517
7
+ data.tar.gz: 5e69567c10388ea9e4a0b52819582fbf6dad1c38d8913853b913273075378167ba04d95e37591cb5858b21f8be2ef80e208c9d646b1799a1588e976ec3fbd0e1
@@ -17,6 +17,37 @@ require 'logger'
17
17
  module Reality
18
18
  module Logging
19
19
  class << self
20
+ # Set the levels on an array of loggers.
21
+ # The levels parameter must be an array matching the number of loggers supplied or a single level.
22
+ # If a block is supplied then the levels are set to the specified values for the duration of the
23
+ # block and then reset to original values after the block completes.
24
+ def set_levels(levels, *loggers)
25
+ if levels.is_a?(Array) && levels.size != loggers.size
26
+ raise "Attempting to set log levels using an array of size #{levels.size} that does not match the number of loggers supplied #{loggers.size}"
27
+ end
28
+
29
+ if block_given?
30
+ saved_levels = []
31
+ loggers.each_with_index do |logger, index|
32
+ saved_levels[index] = logger.level
33
+ end
34
+ begin
35
+ loggers.each_with_index do |logger, index|
36
+ logger.level = levels.is_a?(Array) ? levels[index] : levels
37
+ end
38
+ yield
39
+ ensure
40
+ loggers.each_with_index do |logger, index|
41
+ logger.level = saved_levels[index]
42
+ end
43
+ end
44
+ else
45
+ loggers.each_with_index do |logger, index|
46
+ logger.level = levels.is_a?(Array) ? levels[index] : levels
47
+ end
48
+ end
49
+ end
50
+
20
51
  # noinspection RubyDynamicConstAssignment
21
52
  def configure(module_type, level = ::Logger::INFO, stream = STDOUT)
22
53
  logger = ::Logger.new(stream)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{reality-core}
5
- s.version = '1.4.0'
5
+ s.version = '1.5.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
 
8
8
  s.authors = ['Peter Donald']
@@ -33,4 +33,36 @@ class Reality::TestLogging < Reality::TestCase
33
33
 
34
34
  assert_equal io.string, "Info output\nWarn output\nError output\nDebug output\n"
35
35
  end
36
+
37
+ def test_set_levels
38
+ logger1 = ::Logger.new(STDOUT)
39
+ logger1.level = ::Logger::INFO
40
+ logger2 = ::Logger.new(STDOUT)
41
+ logger2.level = ::Logger::WARN
42
+
43
+ loggers = [logger1, logger2]
44
+
45
+ assert_equal ::Logger::INFO, logger1.level
46
+ assert_equal ::Logger::WARN, logger2.level
47
+
48
+ Reality::Logging.set_levels(::Logger::DEBUG, *loggers) do
49
+ assert_equal ::Logger::DEBUG, logger1.level
50
+ assert_equal ::Logger::DEBUG, logger2.level
51
+ end
52
+
53
+ assert_equal ::Logger::INFO, logger1.level
54
+ assert_equal ::Logger::WARN, logger2.level
55
+
56
+ Reality::Logging.set_levels([::Logger::DEBUG, ::Logger::INFO], *loggers) do
57
+ assert_equal ::Logger::DEBUG, logger1.level
58
+ assert_equal ::Logger::INFO, logger2.level
59
+ end
60
+
61
+ assert_equal ::Logger::INFO, logger1.level
62
+ assert_equal ::Logger::WARN, logger2.level
63
+
64
+ Reality::Logging.set_levels([::Logger::DEBUG, ::Logger::INFO], *loggers)
65
+ assert_equal ::Logger::DEBUG, logger1.level
66
+ assert_equal ::Logger::INFO, logger2.level
67
+ end
36
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reality-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Donald
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-01 00:00:00.000000000 Z
11
+ date: 2016-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest