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 +4 -4
- data/lib/reality/logging.rb +31 -0
- data/reality-core.gemspec +1 -1
- data/test/test_logging.rb +32 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0001afc36f924a295d6b3461b1cdcd78ac7546a
|
4
|
+
data.tar.gz: 739121f92b960be4f5f27f18c0378a23a4727fa5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a968ddcf90298e09ba2ca6d2d6037e33819ffe73f214f30fbcf3cb9f44debdc1113e71d01aba8e3843da9f0981781200f060009082f924b6f6f384092ce8517
|
7
|
+
data.tar.gz: 5e69567c10388ea9e4a0b52819582fbf6dad1c38d8913853b913273075378167ba04d95e37591cb5858b21f8be2ef80e208c9d646b1799a1588e976ec3fbd0e1
|
data/lib/reality/logging.rb
CHANGED
@@ -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)
|
data/reality-core.gemspec
CHANGED
data/test/test_logging.rb
CHANGED
@@ -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
|
+
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-
|
11
|
+
date: 2016-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|