contextual_logger 0.5.0 → 0.5.1.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/contextual_logger.rb +19 -9
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2982d6e312ab94acc9d71c3ed92d127f3c52c1cb
4
- data.tar.gz: 031bc0dc6c086dbbb8f3795db550514814482b38
3
+ metadata.gz: dc1bc39461eb0dd1ba1a76df5ed2bb4b9f693cf7
4
+ data.tar.gz: ca4b6f5152b8e863e5f94b67ccea99c0396b6e9e
5
5
  SHA512:
6
- metadata.gz: 0c07df2056f512b6190f6aee23911f0da948c9625e89b4c0acb0d2449713c84eaa468c4cd20964e2bdf3790b178cff23ccbf8818536a20b01ba41c57c1f1f6f4
7
- data.tar.gz: c91b9641c769391a31209725ad60b2b375c89e60f337c59118cbbf092cd291a23cbceed321e9caf6acf35c3dab898c19c220a473ed3abe351758b73bcea9b43a
6
+ metadata.gz: b2b7152f692ed66a50af3688584ae278038a051335e0fa6e9498eeba0c58fb7d2f186c30f06ec72751034334f9d2e8b7410d69ee454d96416853af8c49348a9c
7
+ data.tar.gz: 618dda35bbafe38dedc55fec558f138161cfb137302e0b7c7d7af4de0b64a891795dbaa1f0b46358ae60da451d5abe537ddb22501f53318a58f05482baad80c1
@@ -59,38 +59,48 @@ module ContextualLogger
59
59
  end
60
60
 
61
61
  def debug(message = nil, context = {})
62
- add_if_enabled(Logger::Severity::DEBUG, message || yield, context: context)
62
+ add(Logger::Severity::DEBUG, message || yield, **context)
63
63
  end
64
64
 
65
65
  def info(message = nil, context = {})
66
- add_if_enabled(Logger::Severity::INFO, message || yield, context: context)
66
+ add(Logger::Severity::INFO, message || yield, **context)
67
67
  end
68
68
 
69
69
  def warn(message = nil, context = {})
70
- add_if_enabled(Logger::Severity::WARN, message || yield, context: context)
70
+ add(Logger::Severity::WARN, message || yield, **context)
71
71
  end
72
72
 
73
73
  def error(message = nil, context = {})
74
- add_if_enabled(Logger::Severity::ERROR, message || yield, context: context)
74
+ add(Logger::Severity::ERROR, message || yield, **context)
75
75
  end
76
76
 
77
77
  def fatal(message = nil, context = {})
78
- add_if_enabled(Logger::Severity::FATAL, message || yield, context: context)
78
+ add(Logger::Severity::FATAL, message || yield, **context)
79
79
  end
80
80
 
81
81
  def unknown(message = nil, context = {})
82
- add_if_enabled(Logger::Severity::UNKNOWN, message || yield, context: context)
82
+ add(Logger::Severity::UNKNOWN, message || yield, **context)
83
83
  end
84
84
 
85
85
  def log_level_enabled?(severity)
86
86
  severity >= level
87
87
  end
88
88
 
89
- def add_if_enabled(severity, message, context:)
89
+ def add(init_severity, message = nil, init_progname = nil, **context) # Ruby will prefer to match hashes up to last ** argument
90
+ severity = init_severity || UNKNOWN
90
91
  if log_level_enabled?(severity)
91
- @progname ||= nil
92
- write_entry_to_log(severity, Time.now, @progname, message, context: current_context_for_thread.deep_merge(context))
92
+ progname = init_progname || @progname
93
+ if message.nil?
94
+ if block_given?
95
+ message = yield
96
+ else
97
+ message = init_progname
98
+ progname = @progname
99
+ end
100
+ end
101
+ write_entry_to_log(severity, Time.now, progname, message, context: current_context_for_thread.deep_merge(context))
93
102
  end
103
+
94
104
  true
95
105
  end
96
106
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contextual_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Ebentier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-12 00:00:00.000000000 Z
11
+ date: 2020-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -65,9 +65,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
65
  version: '0'
66
66
  required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ">="
68
+ - - ">"
69
69
  - !ruby/object:Gem::Version
70
- version: '0'
70
+ version: 1.3.1
71
71
  requirements: []
72
72
  rubyforge_project:
73
73
  rubygems_version: 2.6.13