tlogger 0.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/tlogger/version.rb +1 -1
- data/lib/tlogger.rb +69 -48
- data/samples/basic2.rb +24 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81d536a6b52ad6b35e449b2a19b92d72c16310f6bcb8214b4fce73e4b32785f7
|
4
|
+
data.tar.gz: 4fc37ffecf6133063994e87ae8689641a391f545b52965f37aa28fa3ec316fca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ca899db52484b56c039954d196a563c133f5d9d19d0c0c2d1617c92ef3d8974632721f0461db718a2ba2d3588b005502b6ce610cbe7d9de84c55982fa3aa7a7
|
7
|
+
data.tar.gz: a59e8c857a39769189c98f97dc92d7405268dca08655f85d14eb855164fc936cbd338865bd48bea8c2b418226ff43abb398df99a9064370b80dc58755ba41fac
|
data/Gemfile.lock
CHANGED
data/lib/tlogger/version.rb
CHANGED
data/lib/tlogger.rb
CHANGED
@@ -14,15 +14,23 @@ module Tlogger
|
|
14
14
|
#
|
15
15
|
class TloggerConf
|
16
16
|
include Singleton
|
17
|
-
attr_reader :active_tags, :scoped_tag, :
|
17
|
+
attr_reader :active_tags, :scoped_tag, :blacklisted_tags, :auto_tag
|
18
18
|
#GLOBAL_TAG = :global
|
19
19
|
GLOBAL_TAG = ""
|
20
|
+
INT_TAG = :tlogger
|
20
21
|
|
21
22
|
def initialize
|
22
23
|
@active_tags = []
|
23
|
-
|
24
|
+
# tag added to black listed will not be printed out even the tag is added later in the code path
|
25
|
+
@blacklisted_tags = []
|
24
26
|
@disable_all_tags = false
|
25
27
|
@auto_tag = false
|
28
|
+
# todo
|
29
|
+
# allow to redirect certain tag to specific output. tag: [<config>]
|
30
|
+
@output_map = {}
|
31
|
+
# if output_map is there, then there should be pre created log file with specific output defined in the map. [<config>] => log_instance
|
32
|
+
@output_log = {}
|
33
|
+
# end todo
|
26
34
|
end
|
27
35
|
|
28
36
|
def auto_tag_on
|
@@ -45,11 +53,11 @@ module Tlogger
|
|
45
53
|
@active_tags.delete(tag)
|
46
54
|
end
|
47
55
|
|
48
|
-
def
|
56
|
+
def blacklist_tag(tag)
|
49
57
|
if tag.is_a?(Array)
|
50
|
-
@
|
58
|
+
@blacklisted_tags += tag
|
51
59
|
else
|
52
|
-
@
|
60
|
+
@blacklisted_tags << tag
|
53
61
|
end
|
54
62
|
end
|
55
63
|
|
@@ -61,21 +69,25 @@ module Tlogger
|
|
61
69
|
@disable_all_tags = false
|
62
70
|
end
|
63
71
|
|
64
|
-
def
|
72
|
+
def whitelist_tag(tag)
|
65
73
|
if tag.is_a?(Array)
|
66
74
|
tag.each do |t|
|
67
|
-
@
|
75
|
+
@blacklisted_tags.delete(t)
|
68
76
|
end
|
69
77
|
else
|
70
|
-
@
|
78
|
+
@blacklisted_tags.delete(tag)
|
71
79
|
end
|
72
80
|
end
|
73
|
-
|
81
|
+
|
82
|
+
def whitelist_all_tags
|
83
|
+
@disabled_tags.clear
|
84
|
+
end
|
85
|
+
|
74
86
|
def is_tag_active?(tag)
|
75
87
|
if @disable_all_tags
|
76
88
|
false
|
77
89
|
else
|
78
|
-
@active_tags.include?(tag) and not @disabled_tags.include?(tag)
|
90
|
+
@active_tags.include?(tag) #and not @disabled_tags.include?(tag)
|
79
91
|
end
|
80
92
|
end
|
81
93
|
|
@@ -83,10 +95,6 @@ module Tlogger
|
|
83
95
|
@active_tags.clear
|
84
96
|
end
|
85
97
|
|
86
|
-
def remove_all_disabled_tags
|
87
|
-
@disabled_tags.clear
|
88
|
-
end
|
89
|
-
|
90
98
|
def set_scoped_tag(tag)
|
91
99
|
@scoped_tag = tag
|
92
100
|
end
|
@@ -104,7 +112,8 @@ module Tlogger
|
|
104
112
|
end
|
105
113
|
|
106
114
|
def is_scoped_tag_active?
|
107
|
-
|
115
|
+
#@active_tags.include?(@scoped_tag)
|
116
|
+
not @blacklisted_tags.include?(@scoped_tag)
|
108
117
|
end
|
109
118
|
|
110
119
|
def self.method_missing(mtd,*args,&block)
|
@@ -133,6 +142,8 @@ module Tlogger
|
|
133
142
|
end
|
134
143
|
@tlogger = Logger.new(*args)
|
135
144
|
@tag = TloggerConf::GLOBAL_TAG
|
145
|
+
# disable by default
|
146
|
+
# If there is issue then enable it back in application level
|
136
147
|
self
|
137
148
|
end
|
138
149
|
|
@@ -144,75 +155,85 @@ module Tlogger
|
|
144
155
|
|
145
156
|
def tdebug(tag,*args)
|
146
157
|
with_tag(tag) do
|
147
|
-
debug(*args)
|
158
|
+
self.debug(*args)
|
148
159
|
end
|
149
160
|
self
|
150
161
|
end
|
151
162
|
|
152
163
|
def terror(tag, *args)
|
153
164
|
with_tag(tag) do
|
154
|
-
error(*args)
|
165
|
+
self.error(*args)
|
155
166
|
end
|
156
167
|
self
|
157
168
|
end
|
158
169
|
|
159
170
|
def tinfo(tag, *args)
|
160
171
|
with_tag(tag) do
|
161
|
-
info(*args)
|
172
|
+
self.info(*args)
|
162
173
|
end
|
163
174
|
self
|
164
175
|
end
|
165
176
|
|
166
177
|
def twarn(tag, *args)
|
167
178
|
with_tag(tag) do
|
168
|
-
warn(*args)
|
179
|
+
self.warn(*args)
|
169
180
|
end
|
170
181
|
self
|
171
182
|
end
|
172
183
|
|
184
|
+
def intDebug(msg)
|
185
|
+
#puts TloggerConf.active_tags
|
186
|
+
if TloggerConf.instance.is_tag_active?(TloggerConf::INT_TAG)
|
187
|
+
msg2 = "[#{TloggerConf::INT_TAG}] #{msg}"
|
188
|
+
#puts "intDebug"
|
189
|
+
@tlogger.debug(msg2)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
173
193
|
def method_missing(mtd,*args,&block)
|
174
|
-
|
194
|
+
#@tlogger.debug "[tlogger] method_missing: Method #{mtd}"
|
195
|
+
intDebug("method_missing: #{mtd}")
|
175
196
|
if @tlogger.respond_to?(mtd)
|
176
|
-
|
177
|
-
|
178
|
-
|
197
|
+
|
198
|
+
if PROXY_MTD.include?(mtd)
|
199
|
+
|
200
|
+
if @tag.nil? or @tag.empty?
|
201
|
+
# no tag. Output like normal log
|
202
|
+
@tlogger.send(mtd, *args, &block)
|
203
|
+
|
204
|
+
else
|
205
|
+
|
179
206
|
if TloggerConf.has_scoped_tag?
|
180
207
|
if TloggerConf.is_scoped_tag_active?
|
208
|
+
intDebug("Scoped tag detected")
|
181
209
|
args[0] = "[#{TloggerConf.scoped_tag}] #{args[0]}"
|
182
210
|
@tlogger.send(mtd,*args,&block)
|
183
211
|
end
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
args[0] = "[#{@tag}] #{args[0]}"
|
193
|
-
@tlogger.send(mtd,*args,&block)
|
194
|
-
end
|
195
|
-
elsif TloggerConf.is_auto_tag_on?
|
196
|
-
args = tag_class(*args)
|
197
|
-
@tlogger.send(mtd,*args,&block)
|
198
|
-
end
|
212
|
+
elsif TloggerConf.is_auto_tag_on?
|
213
|
+
intDebug("auto_tag is on...")
|
214
|
+
args = tag_class(*args)
|
215
|
+
@tlogger.send(mtd,*args,&block)
|
216
|
+
elsif TloggerConf.is_tag_active?(@tag)
|
217
|
+
intDebug("Tagged output...")
|
218
|
+
args[0] = "[#{@tag}] #{args[0]}"
|
219
|
+
@tlogger.send(mtd,*args,&block)
|
199
220
|
end
|
200
|
-
|
201
|
-
else
|
202
|
-
@tlogger.send(mtd,*args,&block)
|
221
|
+
|
203
222
|
end
|
204
|
-
# if in proxy method list
|
205
|
-
|
206
|
-
#@tlogger.send(mtd,*args,&block)
|
207
223
|
|
208
|
-
|
209
|
-
|
224
|
+
else
|
225
|
+
intDebug("Not proxy method for logger. Pass to logger to handle. (#{mtd})")
|
226
|
+
## not the debug, info, warn and error method, no need change message
|
210
227
|
@tlogger.send(mtd, *args, &block)
|
211
228
|
end
|
212
|
-
|
229
|
+
|
230
|
+
|
231
|
+
elsif TloggerConf.instance.respond_to?(mtd)
|
213
232
|
# redirect the config method to make it consistent API
|
233
|
+
intDebug("Redirect to TloggerConf for consistancy (#{mtd})")
|
214
234
|
TloggerConf.send(mtd, *args, &block)
|
215
235
|
else
|
236
|
+
intDebug("Call method_missing parent to handle method '#{mtd}'")
|
216
237
|
super
|
217
238
|
end
|
218
239
|
end
|
@@ -229,7 +250,7 @@ module Tlogger
|
|
229
250
|
|
230
251
|
if not @cal.nil? and not @cal.empty?
|
231
252
|
wd = Dir.getwd
|
232
|
-
@scal = @cal[wd.length
|
253
|
+
@scal = @cal[wd.length..-1]
|
233
254
|
args[0] = "[#{@scal}] #{args[0]}"
|
234
255
|
end
|
235
256
|
|
data/samples/basic2.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
l = Tlogger.new
|
4
|
+
l.tag = "dance"
|
5
|
+
#l.activate_tag(Tlogger::TloggerConf::INT_TAG)
|
6
|
+
|
7
|
+
l.debug "here"
|
8
|
+
|
9
|
+
#Tlogger::TloggerConf.blacklist_tag("jan")
|
10
|
+
|
11
|
+
l.with_tag 'jan' do
|
12
|
+
l.debug "inside"
|
13
|
+
puts "inside string"
|
14
|
+
l.debug "outside"
|
15
|
+
end
|
16
|
+
|
17
|
+
l.debug "towards the end"
|
18
|
+
|
19
|
+
l.tdebug :hans, "hans here"
|
20
|
+
l.terror :solo, "Error!"
|
21
|
+
l.tinfo :luke, "This is info!"
|
22
|
+
l.twarn :sky, "Sky is the limit"
|
23
|
+
|
24
|
+
#l.warn "warning!!"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tlogger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Liaw
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/tlogger/version.rb
|
86
86
|
- release.job
|
87
87
|
- samples/basic.rb
|
88
|
+
- samples/basic2.rb
|
88
89
|
- tlogger.gemspec
|
89
90
|
homepage: ''
|
90
91
|
licenses:
|