injectedlogger 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/injectedlogger.rb +10 -5
- data/lib/injectedlogger/logger.rb +5 -0
- data/lib/injectedlogger/version.rb +1 -1
- 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: e65eac7798511cef18b950cd7eed447fa009cbb4
|
4
|
+
data.tar.gz: 20c5a069668a8da8b911f9b53cfddef08144ed72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff4cfe53d9a7882ba25280fd8f1aee00a93238ecd2cd08c7c2c63581979b7e0f574af8c7e69245bb16ad5e64b645b75385aa4e767b097c9da28ce95e2c19feaf
|
7
|
+
data.tar.gz: 2fe88af5c3c9c5787965ba2f57ad49ed4e1d5eb5c371df1e96f6225965ef778c1eb7598627b643b0cc13015e47959d5a537356dbd10fcf8b192a76890dd2ff52
|
data/README.md
CHANGED
@@ -43,6 +43,12 @@ Inject our logger on `Dependency::Logger` and prefix the messages with `'[logger
|
|
43
43
|
InjectedLogger.inject mylogger, prefix: '[logger-for-dep]', on: Dependency::Logger
|
44
44
|
```
|
45
45
|
|
46
|
+
You can also *avoid* depending on InjectedLogger if you call the `inject` method
|
47
|
+
directly on the class/module where your dependency declares the logger:
|
48
|
+
```ruby
|
49
|
+
Dependency::Logger.inject mylogger, prefix: '[logger-for-dep]'
|
50
|
+
```
|
51
|
+
|
46
52
|
### On the code where you want a logger injected:
|
47
53
|
|
48
54
|
This sets up a module with a `logger` method identified as `'dependency-logger'`
|
data/lib/injectedlogger.rb
CHANGED
@@ -40,11 +40,16 @@ module InjectedLogger
|
|
40
40
|
else
|
41
41
|
on = on.singleton_class unless on.is_a? Module
|
42
42
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
InjectedLogger.logger_known as: as, refers_to: on unless as.nil?
|
44
|
+
[:inject, :inject!].each do |m|
|
45
|
+
on.define_singleton_method m do |*args, **options|
|
46
|
+
options.merge! on: on
|
47
|
+
InjectedLogger.public_send m, *args, **options
|
48
|
+
end
|
49
|
+
end
|
50
|
+
on.send :define_method, method_name do
|
46
51
|
# avoid recursion if someone calls logger in the block
|
47
|
-
|
52
|
+
on.send :remove_method, method_name
|
48
53
|
unless InjectedLogger.injected? on: on
|
49
54
|
args = blk ? blk.call : nil
|
50
55
|
InjectedLogger.inject_logger args, required, on: on
|
@@ -57,7 +62,7 @@ module InjectedLogger
|
|
57
62
|
required -= thislogger.level_info[:supported]
|
58
63
|
raise InjectedLogger::UnsupportedLevels.new(required) unless required.empty?
|
59
64
|
end
|
60
|
-
|
65
|
+
on.send :define_method, method_name do
|
61
66
|
thislogger
|
62
67
|
end
|
63
68
|
thislogger.after_hook.call(thislogger) if thislogger.after_hook
|
@@ -25,6 +25,11 @@ module InjectedLogger
|
|
25
25
|
logger[on].after_hook = blk
|
26
26
|
end
|
27
27
|
|
28
|
+
def self.logger_known(as:, refers_to:)
|
29
|
+
logger[as] = logger[refers_to]
|
30
|
+
end
|
31
|
+
singleton_class.send :protected, :logger_known
|
32
|
+
|
28
33
|
class Logger
|
29
34
|
UNKNOWN = :unknown
|
30
35
|
LOGLEVELS = [:debug, :verbose, :notice, :info, :warn, :error, :critical, :fatal, :unknown]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: injectedlogger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alejandro Martinez Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|