tlogger 0.21.1 → 0.26.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: 456f792986f50cb09f12b7bff8e062cb79cb705700e0a8f909f265d5a5f55df2
4
+ data.tar.gz: 16434a962194549c73ed7cc27b2b5a848b02c687716f31f59551a9b9e4202b4c
5
5
  SHA512:
6
- metadata.gz: e9d0e1ee9d45643250732173b473e165573d876b796fc064935c98b2ae1fd06922963db7e86039f0e19f1e1ab1e74d01c4a9d617a1701d27cde1a4fc779cde45
7
- data.tar.gz: 8c3de4cacdfbe62fda3eca5592d5b1cca118112da1e4561544a3b47ae9dddf8dd9f9aa265881c99232f0b01250ed32f4374c3ce46106305a4b9dd5c122512274
6
+ metadata.gz: 7541a13f50860790deb9841cc265c25e37982cb1981de92a4d92fd4fee27473e21aac95a589b7b1f53a6d2afa0dbabf78f53dd499620798d4a1f6d61f222492a
7
+ data.tar.gz: 055e68a34f282a659d8e7699a52f0206a9149f60bb0b0ed8367f14fb466a7c9c35126a129807cf459b55f315c2c488dfaa4c0921a6505292f333b705b571409b
data/.gitignore CHANGED
@@ -8,3 +8,5 @@
8
8
  /tmp/
9
9
 
10
10
  *.log
11
+ *.gem
12
+ Gemfile.lock
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
 
4
+ require 'devops_helper'
5
+
4
6
  Rake::TestTask.new(:test) do |t|
5
7
  t.libs << "test"
6
8
  t.libs << "lib"
@@ -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.26.0"
3
3
  end
data/lib/tlogger.rb CHANGED
@@ -8,13 +8,59 @@ require_relative "tlogger/logger_group"
8
8
  #
9
9
  module Tlogger
10
10
  class Error < StandardError; end
11
-
11
+
12
12
  # shorten the initializer to Tlogger.new instead of the longer Tlogger::Tlogger.new
13
13
  class << self
14
14
  def new(*args,&block)
15
15
  ::Tlogger::Tlogger.new(*args,&block)
16
16
  end
17
+
18
+ # detect if the prompt should be to env or file
19
+ def init
20
+ p is_dev?
21
+ if is_dev?
22
+ new(STDOUT)
23
+ else
24
+ c = output_channel
25
+ new(*c[:path])
26
+ end
27
+ end
28
+
29
+ def set_dev_mode
30
+ ENV["TLOGGER_MODE"] = "dev"
31
+ end
32
+
33
+ def set_production_mode
34
+ ENV.delete("TLOGGER_MODE")
35
+ end
36
+
37
+ def is_dev?
38
+ ENV.keys.include?("TLOGGER_MODE") and ENV["TLOGGER_MODE"].downcase == "dev"
39
+ end
40
+
41
+
42
+ private
43
+ def output_channel
44
+ out = ENV["TLOGGER_OUT"]
45
+ if not out.nil?
46
+ case out
47
+ when "file"
48
+ path = ENV["TLOGGER_OUTPATH"]
49
+ if path =~ /,/
50
+ { mode: :file, path: path.split(",") }
51
+ else
52
+ { mode: :file, path: [path] }
53
+ end
54
+ else
55
+ { mode: :file, path: [nil] }
56
+ end
57
+ else
58
+ { mode: :stdio, path: [nil] }
59
+ end
60
+ end
17
61
  end # class self
18
62
 
63
+
19
64
  end
20
65
 
66
+
@@ -0,0 +1,35 @@
1
+
2
+ require_relative 'tlogger'
3
+
4
+ module Tlogger
5
+ module TloggerHelper
6
+
7
+ module TloggerClassMethods
8
+ def tlogger(tag = nil)
9
+ if @tlogger.nil?
10
+ @tlogger = ::Tlogger.init
11
+ @tlogger.tag = tag if not (tag.nil? and tag.empty?)
12
+ end
13
+ @tlogger
14
+ end
15
+
16
+ def default_logger(tag, dev_mode = false)
17
+ ::Tlogger.set_dev_mode if dev_mode
18
+ tlogger(tag)
19
+ end
20
+ end
21
+
22
+ def self.included(klass)
23
+ klass.extend(TloggerClassMethods)
24
+ end
25
+
26
+ self.extend(TloggerClassMethods)
27
+
28
+ if not respond_to?(:logger)
29
+ def logger
30
+ self.class.tlogger
31
+ end
32
+ end
33
+
34
+ end
35
+ end
data/samples/basic.rb CHANGED
@@ -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
+
data/tlogger.gemspec CHANGED
@@ -27,4 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.bindir = "exe"
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "devops_helper"
30
32
  end
metadata CHANGED
@@ -1,15 +1,29 @@
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.26.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
12
- dependencies: []
11
+ date: 2021-09-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: devops_helper
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: Logger that provides some control over how the log messages are being
14
28
  displayed with conditionally enable and disable certain log messages from showing
15
29
  based on configurations
@@ -31,6 +45,7 @@ files:
31
45
  - lib/tlogger/logger_group.rb
32
46
  - lib/tlogger/tlogger.rb
33
47
  - lib/tlogger/version.rb
48
+ - lib/tlogger_helper.rb
34
49
  - samples/basic.rb
35
50
  - samples/group.rb
36
51
  - tlogger.gemspec
@@ -39,7 +54,7 @@ licenses:
39
54
  - MIT
40
55
  metadata:
41
56
  homepage_uri: https://github.com/chrisliaw/tlogger
42
- post_install_message:
57
+ post_install_message:
43
58
  rdoc_options: []
44
59
  require_paths:
45
60
  - lib
@@ -54,8 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
69
  - !ruby/object:Gem::Version
55
70
  version: '0'
56
71
  requirements: []
57
- rubygems_version: 3.0.8
58
- signing_key:
72
+ rubygems_version: 3.2.22
73
+ signing_key:
59
74
  specification_version: 4
60
75
  summary: Logger that added contextual information to the log messages
61
76
  test_files: []