tlogger 0.21.1 → 0.22.0

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: 299b85474257a420194ddf5b6d1bf52b825b92fceb7349f37885b81918fa849c
4
- data.tar.gz: 78af413f1ff7add4254fff72d46a17dd9dd0a9677f9497beacb369c2ee5844d3
3
+ metadata.gz: e2097702e7fcefd385c55d485f0ef8f26c16b6a4f523064be6f05e497ae510b5
4
+ data.tar.gz: 295a7c220f3df575dd88c6062bf1c6f77a6f902122dc5adba06b86481b268df6
5
5
  SHA512:
6
- metadata.gz: e9d0e1ee9d45643250732173b473e165573d876b796fc064935c98b2ae1fd06922963db7e86039f0e19f1e1ab1e74d01c4a9d617a1701d27cde1a4fc779cde45
7
- data.tar.gz: 8c3de4cacdfbe62fda3eca5592d5b1cca118112da1e4561544a3b47ae9dddf8dd9f9aa265881c99232f0b01250ed32f4374c3ce46106305a4b9dd5c122512274
6
+ metadata.gz: ca42907248b81dc572c21475b7db339d2f3caaa017854f0b9af465f7950b524a270180f7dcae7572f96b5f97ce08060f9083809c5620884e56860883c4583cf8
7
+ data.tar.gz: c8f1fe748c293b53cbe30c540b591cfc6c23ea9323ec65420d3f2f2c4be40910ba1ba423b0950d81ebfd86d3bd9f775dd642f1680302448b6822e915e34a59a1
@@ -226,11 +226,11 @@ module Tlogger
226
226
  if is_genabled?(key) and not tag_disabled?(key.to_sym)
227
227
  if block
228
228
  out = Proc.new { block.call }
229
- args = [ format_message(args[0]) ]
229
+ args = [ format_message(key) ]
230
230
  else
231
231
  str = args[1]
232
232
  out = Proc.new { str }
233
- args = [ format_message(args[0]) ]
233
+ args = [ format_message(key) ]
234
234
  end
235
235
 
236
236
  mtd = mtd.to_s[1..-1].to_sym
@@ -245,11 +245,11 @@ module Tlogger
245
245
 
246
246
  if block
247
247
  out = Proc.new { block.call }
248
- args = [ format_message(args[0]) ]
248
+ args = [ format_message(key) ]
249
249
  else
250
250
  str = args[1]
251
251
  out = Proc.new { str }
252
- args = [ format_message(args[0]) ]
252
+ args = [ format_message(key) ]
253
253
  end
254
254
 
255
255
  msg = out.call
@@ -262,6 +262,34 @@ module Tlogger
262
262
 
263
263
  end
264
264
 
265
+ elsif [:ifdebug, :iferror, :ifinfo, :ifwarn].include?(mtd)
266
+
267
+ cond = args[0]
268
+ key = args[1]
269
+
270
+ if cond.is_a?(Proc)
271
+ cond = cond.call
272
+ end
273
+
274
+ if is_genabled?(key) and not tag_disabled?(key) and cond
275
+
276
+ if block
277
+ out = Proc.new { block.call }
278
+ args = [ format_message(key) ]
279
+ else
280
+ str = args[2]
281
+ out = Proc.new { str }
282
+ args = [ format_message(key) ]
283
+ end
284
+
285
+ msg = out.call
286
+ if not (msg.nil? or msg.empty?)
287
+ mtd = mtd.to_s[2..-1].to_sym
288
+ @logger.send(mtd, *args, &out)
289
+ end
290
+
291
+ end
292
+
265
293
  elsif @logger.respond_to?(mtd)
266
294
  @logger.send(mtd, *args, &block)
267
295
  else
@@ -1,3 +1,3 @@
1
1
  module Tlogger
2
- VERSION = "0.21.1"
2
+ VERSION = "0.22.0"
3
3
  end
@@ -32,6 +32,7 @@ log.debug "Outside block. Shall take default tag '#{log.tag}'"
32
32
 
33
33
  log.debug "About to show log message only show once. This can be useful if it is a warning which only print out per run."
34
34
  (0..4).each do |i|
35
+ # Show message once only
35
36
  # one time message tie to key
36
37
  # Means if the message is under specific key and already prompted, it will skip
37
38
  # Else it will be printed
@@ -60,3 +61,13 @@ log.debug "I'm inherited from key :global so I'm also not visible" # due to on_
60
61
  log.tinfo :global, "Gosh! I've been turned off by default" # due to on_all_except(:global) this line shall not be printed
61
62
  log.twarn :local, "I'm free!" # this line will show up because all is on
62
63
 
64
+ x = 2
65
+ # Log only print if the first parameters is true.
66
+ log.ifdebug(x == 2, :ifdebug, "Debug : x == 2!")
67
+ log.iferror(x == 2, :iferror, "Err : x == 2!")
68
+ log.ifinfo(x == 2, :ifinfo, "Info: x == 2!")
69
+ log.ifwarn(x == 2, :ifwarn, "Warn: x == 2!")
70
+
71
+ # first param also can be a proc
72
+ log.ifdebug Proc.new { x == 2 }, :ifdebug2, "Debug 2 : x == 2!"
73
+
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.21.1
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-16 00:00:00.000000000 Z
11
+ date: 2020-10-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Logger that provides some control over how the log messages are being
14
14
  displayed with conditionally enable and disable certain log messages from showing
@@ -39,7 +39,7 @@ licenses:
39
39
  - MIT
40
40
  metadata:
41
41
  homepage_uri: https://github.com/chrisliaw/tlogger
42
- post_install_message:
42
+ post_install_message:
43
43
  rdoc_options: []
44
44
  require_paths:
45
45
  - lib
@@ -54,8 +54,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  requirements: []
57
- rubygems_version: 3.0.8
58
- signing_key:
57
+ rubygems_version: 3.1.4
58
+ signing_key:
59
59
  specification_version: 4
60
60
  summary: Logger that added contextual information to the log messages
61
61
  test_files: []