intake 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/intake/logger.rb +12 -5
- data/lib/intake/repository.rb +21 -8
- data/lib/intake/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0da496aeddc3a2af915242e66b0dde99077f9db6fad39b1aa608db88c4b3c7d7
|
4
|
+
data.tar.gz: 3e6f74f74938ca1ac38c4c6ffef7f6518a159ce208b26cd6fc442e1063e7d2b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b79c556355cd93395449943a59e1fda06af7081357fd94581a5ae8e192b10b3e5e113e8848b66c56cc9ab1b7e0242bbdbc1217c65c845dedf2e88f931e252c0
|
7
|
+
data.tar.gz: ed1959f3d7d111bd7acfb62412eec03c76767ef2cdf57ceab35ac5c0640dbc516cf5cf5e0f15c69367dab5a6f1ff7781264bcdd0f43f86c9a4aec95ba1f62929
|
data/lib/intake/logger.rb
CHANGED
@@ -11,31 +11,38 @@ require_relative 'repository'
|
|
11
11
|
module Intake
|
12
12
|
# Logger is a object that captures log event and forward that to event sinks.
|
13
13
|
class Logger
|
14
|
+
DEFAULT_LEVEL = ::Intake::Level[:info]
|
14
15
|
class << self
|
15
16
|
def [](name)
|
16
|
-
::Intake::Repository.instance.get_or_add(name) do |logger_name|
|
17
|
-
Logger.new(logger_name)
|
17
|
+
::Intake::Repository.instance.get_or_add(name) do |logger_name, parent|
|
18
|
+
Logger.new(logger_name, parent: parent)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
23
|
attr_reader :name
|
23
24
|
|
24
|
-
def initialize(name)
|
25
|
+
def initialize(name, parent: nil)
|
25
26
|
validate_name(name)
|
26
27
|
|
27
28
|
@name = name
|
28
|
-
@level =
|
29
|
+
@level = nil
|
30
|
+
@parent = parent
|
29
31
|
end
|
30
32
|
|
31
33
|
def level?(level)
|
32
|
-
|
34
|
+
self.level.val <= level.val
|
35
|
+
end
|
36
|
+
|
37
|
+
def level
|
38
|
+
@level || @parent&.level || DEFAULT_LEVEL
|
33
39
|
end
|
34
40
|
|
35
41
|
def level=(level)
|
36
42
|
@level = case level
|
37
43
|
when String, Symbol then ::Intake::Level[level.to_sym]
|
38
44
|
when ::Intake::Level then level
|
45
|
+
when nil then nil
|
39
46
|
end
|
40
47
|
end
|
41
48
|
|
data/lib/intake/repository.rb
CHANGED
@@ -19,17 +19,16 @@ module Intake
|
|
19
19
|
@store.key? canonize_name(name)
|
20
20
|
end
|
21
21
|
|
22
|
-
def get_or_add(name)
|
23
|
-
|
24
|
-
logger = @store[name]
|
22
|
+
def get_or_add(name, &block)
|
23
|
+
return nil if name.nil?
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@store
|
25
|
+
name = canonize_name(name)
|
26
|
+
unless @store.key? name
|
27
|
+
@mutex.synchronize do
|
28
|
+
create_logger_unsafe(name, &block) unless @store.key? name
|
30
29
|
end
|
31
30
|
end
|
32
|
-
|
31
|
+
@store[name]
|
33
32
|
end
|
34
33
|
|
35
34
|
private
|
@@ -44,8 +43,22 @@ module Intake
|
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
46
|
+
def parent_name(name)
|
47
|
+
separator_rindex = name.rindex('::')
|
48
|
+
separator_rindex.nil? ? 'root' : name[0, separator_rindex]
|
49
|
+
end
|
50
|
+
|
47
51
|
def module_name(mod)
|
48
52
|
mod.name
|
49
53
|
end
|
54
|
+
|
55
|
+
def create_logger_unsafe(name, &block)
|
56
|
+
unless name == 'root'
|
57
|
+
parent_logger_name = parent_name(name)
|
58
|
+
parent_logger = @store[parent_logger_name] || create_logger_unsafe(parent_logger_name, &block)
|
59
|
+
end
|
60
|
+
@store[name] = block.call(name, parent_logger) unless @store.key?(name)
|
61
|
+
@store[name]
|
62
|
+
end
|
50
63
|
end
|
51
64
|
end
|
data/lib/intake/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: intake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Maraev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|