prefab-cloud-ruby 0.19.0 → 0.20.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: f56ee15a73bef27dbb37cfbc4df7b1004543664ea7b5defc5ae6afbb738a4c23
4
- data.tar.gz: 151d525aca5d58ee1098fed1f6e87037ee6b2cc8570985f2a922ec028cc3d394
3
+ metadata.gz: d1d4612e27cae5a4e66065a16d8d70cb0b1c7120770eac8c7e09ce3ca0e48e82
4
+ data.tar.gz: 1d1f50b6b4605729b93d62194b17ed9a1fca739f435ec2a4e682482a293bffe6
5
5
  SHA512:
6
- metadata.gz: 9d48de76dc679c635a9530625aa0feedd6ddb9193023b98e5c24247f6eded562e9ffcca770116dc5a1bc7dc60a0e7fad2f828f31b791c771c7d3aa587daf77bd
7
- data.tar.gz: da2371a89c4886ac22d2ce5ef0b7b2e8b732aa8ac2600a699b1598cc1c9138c9a99e075df944d911f790f385ffea81c2b186aaf29d6b40ed7c5f05247d41d22b
6
+ metadata.gz: ed5a04b2a16a79b0963d9af2dd71955141fdd06e7d73a4897adf74245435cf33239f78b08bbde797b7420b7e988fbb76e5e4333e6da5350f1037502949c469e7
7
+ data.tar.gz: 1b6f556bb94a31c272d5cd3c585860cacb4698be61830379c1a1a7e2d2fdcb461c02777e0c6fdb6a2cc939dcb070a27237506bd3c21d69ccd723ec50dccfbf2a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.19.0
1
+ 0.20.0
@@ -43,15 +43,13 @@ module Prefab
43
43
  end
44
44
 
45
45
  def log(message, path, progname, severity, &block)
46
- level = level_of(path)
47
- progname = "#{path}: #{progname}"
48
46
  severity ||= Logger::UNKNOWN
49
- if @logdev.nil? || severity < level || @silences[local_log_id]
47
+ if @logdev.nil? || severity < level_of(path) || @silences[local_log_id]
50
48
  return true
51
49
  end
52
- if progname.nil?
53
- progname = @progname
54
- end
50
+
51
+ progname = "#{path}: #{progname || @progname}"
52
+
55
53
  if message.nil?
56
54
  if block_given?
57
55
  message = yield
@@ -60,6 +58,7 @@ module Prefab
60
58
  progname = @progname
61
59
  end
62
60
  end
61
+
63
62
  @logdev.write(
64
63
  format_message(format_severity(severity), Time.now, progname, message))
65
64
  true
@@ -19,7 +19,7 @@ module Prefab
19
19
  attr_reader :prefab_envs
20
20
 
21
21
  DEFAULT_LOG_FORMATTER = proc { |severity, datetime, progname, msg|
22
- "#{severity.ljust(5)} #{datetime}: #{progname} #{msg}\n"
22
+ "#{severity.ljust(5)} #{datetime}:#{" " if progname}#{progname} #{msg}\n"
23
23
  }
24
24
 
25
25
  module ON_INITIALIZATION_FAILURE
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: prefab-cloud-ruby 0.19.0 ruby lib
5
+ # stub: prefab-cloud-ruby 0.20.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "prefab-cloud-ruby".freeze
9
- s.version = "0.19.0"
9
+ s.version = "0.20.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Jeff Dwyer".freeze]
14
- s.date = "2022-11-19"
14
+ s.date = "2022-12-02"
15
15
  s.description = "RateLimits & Config as a service".freeze
16
16
  s.email = "jdwyer@prefab.cloud".freeze
17
17
  s.extra_rdoc_files = [
data/test/test_logger.rb CHANGED
@@ -115,18 +115,54 @@ class TestCLogger < Minitest::Test
115
115
  prefix = 'my.own.prefix'
116
116
  message = 'this is a test'
117
117
 
118
- io = StringIO.new
119
- options = Prefab::Options.new(logdev: io, log_prefix: prefix, prefab_datasources: Prefab::Options::DATASOURCES::LOCAL_ONLY)
120
- prefab = Prefab::Client.new(options)
118
+ prefab, io = captured_logger(log_prefix: prefix)
121
119
 
122
120
  prefixed_logger = prefab.log
123
121
  prefixed_logger.error message
124
122
 
125
- assert_logged io.string, 'ERROR', "#{prefix}.test.test_logger.test_logging_with_prefix", message
123
+ assert_logged io, 'ERROR', "#{prefix}.test.test_logger.test_logging_with_prefix", message
124
+ end
125
+
126
+ def test_logging_without_a_progname
127
+ prefab, io = captured_logger
128
+ message = "MY MESSAGE"
129
+
130
+ prefab.log.error message
131
+
132
+ assert_logged io, 'ERROR', "test.test_logger.test_logging_without_a_progname", message
133
+ end
134
+
135
+ def test_logging_without_a_progname_or_message
136
+ prefab, io = captured_logger
137
+
138
+ prefab.log.error
139
+
140
+ assert_logged io, 'ERROR', "test.test_logger.test_logging_without_a_progname_or_message", ""
141
+ end
142
+
143
+ def test_logging_with_a_progname
144
+ prefab, io = captured_logger
145
+ message = "MY MESSAGE"
146
+
147
+ prefab.log.progname = "MY_PROGNAME"
148
+ prefab.log.error message
149
+
150
+ assert_logged io, 'ERROR', "MY_PROGNAME test.test_logger.test_logging_with_a_progname", message
151
+ end
152
+
153
+ def test_logging_with_a_progname_and_no_message
154
+ prefab, io = captured_logger
155
+
156
+ prefab.log.progname = "MY_PROGNAME"
157
+ prefab.log.error
158
+
159
+ assert_logged io, 'ERROR', "MY_PROGNAME test.test_logger.test_logging_with_a_progname_and_no_message", "MY_PROGNAME"
126
160
  end
127
161
 
128
- def assert_logged(log_line, level, path, message)
129
- assert_match(/#{level} \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-\+]?\d+: #{path}: #{message}\n/, log_line)
162
+ private
163
+
164
+ def assert_logged(logged_io, level, path, message)
165
+ assert_match(/#{level} \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-\+]?\d+: #{path}: #{message}\n/, logged_io.string)
130
166
  end
131
167
 
132
168
  def mock_logger_expecting pattern, configs = {}, calls: 1
@@ -144,4 +180,15 @@ class TestCLogger < Minitest::Test
144
180
  logger.set_config_client(MockConfigClient.new(configs))
145
181
  [logger, mock_logdev]
146
182
  end
183
+
184
+ def captured_logger(options = {})
185
+ io = StringIO.new
186
+ options = Prefab::Options.new(**options.merge(
187
+ logdev: io,
188
+ prefab_datasources: Prefab::Options::DATASOURCES::LOCAL_ONLY
189
+ ))
190
+ prefab = Prefab::Client.new(options)
191
+
192
+ return [prefab, io]
193
+ end
147
194
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prefab-cloud-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.0
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Dwyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-19 00:00:00.000000000 Z
11
+ date: 2022-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby