tlogger 0.21.0 → 0.25.1

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: 7e5e945c26521b256ba6c54e4bfa3cdabd734872bb98d2ca5e1f5ce5e5005638
4
- data.tar.gz: 80622dc6905d7f80c05bd2f2c81a987bcafa089fb21602e132e165e87f03cc2a
3
+ metadata.gz: b4232ba1eb83e3cd042ea70c67272fb9598b74d0b295494a9ee540b3c6491c92
4
+ data.tar.gz: e6c805f3229fe09d4a2b1bf1b9d18e1a0bcd243ae2839eaa096664dba2a3bcbb
5
5
  SHA512:
6
- metadata.gz: a260719058fe3c4cc1ab51cc4540d52a92c56cb82a5cc1a8088fb4affbf9e662b4250e73efe6ed40a44a6ad879a4da88e971b2a4ea4be456def6ad37beeeb305
7
- data.tar.gz: c72dee13fc95be607c60726749d10ea3de968e46c35c21495cdd245bbfa2fe0b93576ab3d7e96d4f365c409781f3041b37e6e78c879cf2c33271ff9f2425356a
6
+ metadata.gz: 5860e1862e58902dc358529e35891900e377fc0055bd8ed9fc9dfe653c49d2f719f8e507705e9372b462678979595c00bd607298cdfe296b6d3d2d14b63ba268
7
+ data.tar.gz: 3dc82d00fb68f8baf5d9d4115be52c8bca5b841768178fb036889873020b9ea559acf3b5da076692872865fb963eee39a9c72351eb9df975e45bc8d51281bedb
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.0"
2
+ VERSION = "0.25.1"
3
3
  end
data/lib/tlogger.rb CHANGED
@@ -8,4 +8,55 @@ require_relative "tlogger/logger_group"
8
8
  #
9
9
  module Tlogger
10
10
  class Error < StandardError; end
11
+
12
+ # shorten the initializer to Tlogger.new instead of the longer Tlogger::Tlogger.new
13
+ class << self
14
+ def new(*args,&block)
15
+ ::Tlogger::Tlogger.new(*args,&block)
16
+ end
17
+
18
+ # detect if the prompt should be to env or file
19
+ def init
20
+ if is_dev?
21
+ new(STDOUT)
22
+ else
23
+ c = output_channel
24
+ new(*c[:path])
25
+ end
26
+ end
27
+
28
+ def set_dev_mode
29
+ ENV["TLOGGER_MODE"] = "dev"
30
+ end
31
+
32
+ def set_production_mode
33
+ ENV.delete("TLOGGER_MODE")
34
+ end
35
+
36
+ def is_dev?
37
+ ENV.keys.include?("TLOGGER_MODE") and ENV["TLOGGER_MODE"].downcase == "dev"
38
+ end
39
+
40
+ private
41
+ def output_channel
42
+ out = ENV["TLOGGER_OUT"]
43
+ if not out.nil?
44
+ case out
45
+ when "file"
46
+ path = ENV["TLOGGER_OUTPATH"]
47
+ if path =~ /,/
48
+ { mode: :file, path: path.split(",") }
49
+ else
50
+ { mode: :file, path: [path] }
51
+ end
52
+ else
53
+ { mode: :file, path: [nil] }
54
+ end
55
+ else
56
+ { mode: :stdio, path: [nil] }
57
+ end
58
+ end
59
+ end # class self
60
+
11
61
  end
62
+
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.0
4
+ version: 0.25.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-08 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2021-09-09 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
@@ -54,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
68
  - !ruby/object:Gem::Version
55
69
  version: '0'
56
70
  requirements: []
57
- rubygems_version: 3.0.8
71
+ rubygems_version: 3.2.22
58
72
  signing_key:
59
73
  specification_version: 4
60
74
  summary: Logger that added contextual information to the log messages