tlogger 0.3 → 0.4

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
  SHA256:
3
- metadata.gz: 25cccca4c4679c7df165e4f5a3ea3b6360095d6d62f0a3421fbfd127b509b5b3
4
- data.tar.gz: 2a654ffd791c1a1079b6cb192b7844d657195537e34fd8f53ffd355867229a05
3
+ metadata.gz: b86e2cb6836e268176b31f6ce4e7d6fcfd819f736988ae110dbbd00d40260881
4
+ data.tar.gz: 17b63a9ee7a5d60c9f22381d3da9b2107d854d5f445d24e41410aee51d9026d9
5
5
  SHA512:
6
- metadata.gz: 1ed029cb7460c3b124acec147784310457467c5d3f59ecb729c5279f9def19193302a6acbde670d0fb6883822d79291b9c7ae3e2997fc8891370a0c7bde3f3eb
7
- data.tar.gz: 0d1f0ba6eaaf1683a5406639718eab684fb69257b0eaf745ac90d25999612dbbdc5f90317d1e4ab68fb7ec8dff58c350ffef2cb871945744c7c32925e3f58d7e
6
+ metadata.gz: 998b911a6eb9195d62aed020e36e86422c36081bb3a95eb8eb4c787b032b97f2b804094b33ebfd4b60a41fc3ac3f26f5e72867db9684ee6a0587e5822eea6f26
7
+ data.tar.gz: 6d7b8f29e67dc041e3787a2e69ad958a72df10f3da7e3d38d00800a445a1dbbd1ed8570b7ebf92dc8c607a08cd78b5ef7348369f02f2c5cbfaf7207fb9141235
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tlogger (0.1.0)
4
+ tlogger (0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  module Tlogger
2
- VERSION = "0.3"
2
+ VERSION = "0.4"
3
3
  end
data/lib/tlogger.rb CHANGED
@@ -15,10 +15,11 @@ module Tlogger
15
15
  class TloggerConf
16
16
  include Singleton
17
17
  attr_reader :active_tags, :scoped_tag, :disabled_tags, :auto_tag
18
- GLOBAL_TAG = :global
18
+ #GLOBAL_TAG = :global
19
+ GLOBAL_TAG = ""
19
20
 
20
21
  def initialize
21
- @active_tags = [:global]
22
+ @active_tags = []
22
23
  @disabled_tags = []
23
24
  @disable_all_tags = false
24
25
  @auto_tag = false
@@ -56,6 +57,10 @@ module Tlogger
56
57
  @disable_all_tags = true
57
58
  end
58
59
 
60
+ def all_tags_on
61
+ @disable_all_tags = false
62
+ end
63
+
59
64
  def enable_tag(tag)
60
65
  if tag.is_a?(Array)
61
66
  tag.each do |t|
@@ -98,6 +103,10 @@ module Tlogger
98
103
  end
99
104
  end
100
105
 
106
+ def is_scoped_tag_active?
107
+ not @disabled_tags.include?(@scoped_tag)
108
+ end
109
+
101
110
  def self.method_missing(mtd,*args,&block)
102
111
  if TloggerConf.instance.respond_to?(mtd)
103
112
  TloggerConf.instance.send(mtd,*args,&block)
@@ -115,9 +124,13 @@ module Tlogger
115
124
  #
116
125
  class << self
117
126
  attr_accessor :tag
127
+ include Tlogger
118
128
 
119
129
  PROXY_MTD = [:debug, :info, :error, :warn]
120
130
  def new(*args)
131
+ if args.length == 0
132
+ args << STDOUT
133
+ end
121
134
  @tlogger = Logger.new(*args)
122
135
  @tag = TloggerConf::GLOBAL_TAG
123
136
  self
@@ -129,36 +142,82 @@ module Tlogger
129
142
  self
130
143
  end
131
144
 
145
+ def tdebug(tag,*args)
146
+ with_tag(tag) do
147
+ debug(*args)
148
+ end
149
+ self
150
+ end
151
+
152
+ def terror(tag, *args)
153
+ with_tag(tag) do
154
+ error(*args)
155
+ end
156
+ self
157
+ end
158
+
159
+ def tinfo(tag, *args)
160
+ with_tag(tag) do
161
+ info(*args)
162
+ end
163
+ self
164
+ end
165
+
166
+ def twarn(tag, *args)
167
+ with_tag(tag) do
168
+ warn(*args)
169
+ end
170
+ self
171
+ end
172
+
132
173
  def method_missing(mtd,*args,&block)
174
+ @tlogger.debug "[tlogger] method_missing: Method #{mtd}"
133
175
  if @tlogger.respond_to?(mtd)
134
176
  if TloggerConf.is_tag_active?(@tag) or TloggerConf.has_scoped_tag?
135
177
  if PROXY_MTD.include?(mtd)
178
+ # All messages should be tagged under this section...
136
179
  if TloggerConf.has_scoped_tag?
137
- args[0] = "[#{TloggerConf.scoped_tag}] #{args[0]}"
180
+ if TloggerConf.is_scoped_tag_active?
181
+ args[0] = "[#{TloggerConf.scoped_tag}] #{args[0]}"
182
+ @tlogger.send(mtd,*args,&block)
183
+ end
138
184
  else
139
185
  if not @tag.nil? and not @tag.empty?
140
186
  if @tag == TloggerConf::GLOBAL_TAG
141
187
  if TloggerConf.is_auto_tag_on?
142
188
  args = tag_class(*args)
189
+ @tlogger.send(mtd,*args,&block)
143
190
  end
144
191
  else
145
192
  args[0] = "[#{@tag}] #{args[0]}"
193
+ @tlogger.send(mtd,*args,&block)
146
194
  end
147
195
  elsif TloggerConf.is_auto_tag_on?
148
196
  args = tag_class(*args)
197
+ @tlogger.send(mtd,*args,&block)
149
198
  end
150
199
  end
151
-
200
+
201
+ else
202
+ @tlogger.send(mtd,*args,&block)
152
203
  end
204
+ # if in proxy method list
153
205
 
154
- @tlogger.send(mtd,*args,&block)
206
+ #@tlogger.send(mtd,*args,&block)
207
+
208
+ elsif TloggerConf.is_auto_tag_on?
209
+ args = tag_class(*args)
210
+ @tlogger.send(mtd, *args, &block)
155
211
  end
156
212
  elsif TloggerConf.respond_to?(mtd)
213
+ # redirect the config method to make it consistent API
157
214
  TloggerConf.send(mtd, *args, &block)
158
215
  else
159
216
  super
160
217
  end
161
218
  end
219
+ # end method_missing
220
+ #
162
221
 
163
222
  private
164
223
  def tag_class(*args)
@@ -167,9 +226,18 @@ module Tlogger
167
226
  @cal = c
168
227
  break
169
228
  end
170
- args[0] = "[#{@cal}] #{args[0]}"
229
+
230
+ if not @cal.nil? and not @cal.empty?
231
+ wd = Dir.getwd
232
+ @scal = @cal[wd.length+1..-1]
233
+ args[0] = "[#{@scal}] #{args[0]}"
234
+ end
235
+
236
+ args
237
+ #args[0] = "[#{@cal}] #{args[0]}"
171
238
  end
172
-
239
+ # end tag_class()
240
+ #
173
241
  end
174
242
  #
175
243
  # end class definition
@@ -178,7 +246,7 @@ module Tlogger
178
246
 
179
247
  def with_tag(tag,&block)
180
248
  if block
181
- TloggerConf.instance.set_scoped_tag(tag)
249
+ TloggerConf.instance.set_scoped_tag(tag) #if not TloggerConf.instance.disabled_tags.include?(tag)
182
250
  block.call
183
251
  TloggerConf.instance.clear_scoped_tag
184
252
  end
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: '0.3'
4
+ version: '0.4'
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-07-10 00:00:00.000000000 Z
11
+ date: 2019-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler