berkeley_library-logging 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +388 -0
  3. data/.idea/inspectionProfiles/Project_Default.xml +17 -0
  4. data/.idea/logging.iml +139 -0
  5. data/.idea/modules.xml +8 -0
  6. data/.idea/vcs.xml +6 -0
  7. data/.rubocop.yml +271 -0
  8. data/.ruby-version +1 -0
  9. data/.simplecov +4 -0
  10. data/.travis.yml +9 -0
  11. data/CHANGES.md +12 -0
  12. data/Dockerfile +57 -0
  13. data/Gemfile +3 -0
  14. data/Jenkinsfile +21 -0
  15. data/LICENSE.md +21 -0
  16. data/README.md +47 -0
  17. data/Rakefile +31 -0
  18. data/berkeley_library-logging.gemspec +47 -0
  19. data/docker-compose.yml +15 -0
  20. data/lib/berkeley_library/logging.rb +38 -0
  21. data/lib/berkeley_library/logging/configurator.rb +41 -0
  22. data/lib/berkeley_library/logging/env.rb +38 -0
  23. data/lib/berkeley_library/logging/events.rb +39 -0
  24. data/lib/berkeley_library/logging/formatters.rb +54 -0
  25. data/lib/berkeley_library/logging/logger.rb +12 -0
  26. data/lib/berkeley_library/logging/loggers.rb +79 -0
  27. data/lib/berkeley_library/logging/module_info.rb +16 -0
  28. data/lib/berkeley_library/logging/railtie.rb +15 -0
  29. data/lib/berkeley_library/logging/tagged_logging_extensions.rb +21 -0
  30. data/rakelib/.rubocop.yml +4 -0
  31. data/rakelib/bundle.rake +8 -0
  32. data/rakelib/coverage.rake +36 -0
  33. data/rakelib/gem.rake +56 -0
  34. data/rakelib/rubocop.rake +14 -0
  35. data/rakelib/spec.rake +31 -0
  36. data/spec/.rubocop.yml +27 -0
  37. data/spec/rails/ucblit/logging/configurator_spec.rb +101 -0
  38. data/spec/rails/ucblit/logging/env_spec.rb +25 -0
  39. data/spec/rails/ucblit/logging/formatters_spec.rb +44 -0
  40. data/spec/rails/ucblit/logging/loggers_spec.rb +117 -0
  41. data/spec/rails/ucblit/logging/railtie_spec.rb +46 -0
  42. data/spec/rails/ucblit/logging_spec.rb +132 -0
  43. data/spec/rails_helper.rb +15 -0
  44. data/spec/spec_helper.rb +34 -0
  45. data/spec/standalone/ucblit/logging/configurator_spec.rb +103 -0
  46. data/spec/standalone/ucblit/logging/formatters_spec.rb +44 -0
  47. data/spec/standalone/ucblit/logging/loggers_spec.rb +278 -0
  48. data/spec/standalone/ucblit/logging_spec.rb +133 -0
  49. data/spec/standalone_helper.rb +25 -0
  50. metadata +363 -0
@@ -0,0 +1,133 @@
1
+ require 'standalone_helper'
2
+
3
+ module BerkeleyLibrary
4
+ describe Logging do
5
+
6
+ def logger_defined?
7
+ Logging.instance_variable_defined?(:@logger)
8
+ end
9
+
10
+ def reset_logger!
11
+ Logging.instance_variable_set(:@logger, @logging_logger_orig)
12
+ end
13
+
14
+ def undefine_logger!
15
+ Logging.send(:remove_instance_variable, :@logger) if logger_defined?
16
+ end
17
+
18
+ def new_mock_logger
19
+ mock_logger_class = Class.new do
20
+ def respond_to?(*args)
21
+ %i[debug info warn error].include?(args[0].to_sym) || super
22
+ end
23
+ end
24
+
25
+ mock_logger_class.new
26
+ end
27
+
28
+ before(:each) do
29
+ if (@logger_was_defined = logger_defined?)
30
+ @logging_logger_orig = Logging.instance_variable_get(:@logger)
31
+ undefine_logger!
32
+ end
33
+
34
+ # Outside Rails, `default_logger` usually returns a new logger every time, so to make this
35
+ # test simpler, we mock it to always return the same object
36
+ persistent_default_logger = new_mock_logger
37
+ allow(Logging::Loggers).to receive(:default_logger).and_return(persistent_default_logger)
38
+ end
39
+
40
+ after(:each) do
41
+ @logger_was_defined ? reset_logger! : undefine_logger!
42
+ end
43
+
44
+ describe 'class methods' do
45
+ describe :logger do
46
+ it 'returns the default logger' do
47
+ logger = Logging::Loggers.default_logger
48
+ expect(Logging.logger).to eq(logger)
49
+ end
50
+
51
+ it 'returns a set logger' do
52
+ logger = new_mock_logger
53
+ Logging.logger = logger
54
+ expect(Logging.logger).to be(logger)
55
+ end
56
+
57
+ end
58
+
59
+ describe :logger= do
60
+ it 'rejects a non-logger' do
61
+ original_logger = Logging.logger
62
+ expect { Logging.logger = Object.new }.to raise_error(ArgumentError)
63
+ expect(Logging.logger).to eq(original_logger)
64
+ end
65
+
66
+ it 'can be reset to default with nil' do
67
+ default_logger = Logging::Loggers.default_logger
68
+ Logging.logger = new_mock_logger
69
+ Logging.logger = nil
70
+ expect(Logging.logger).to eq(default_logger)
71
+ end
72
+ end
73
+ end
74
+
75
+ describe 'included' do
76
+ attr_reader :logificator
77
+
78
+ before(:each) do
79
+ @logificator = Object.new
80
+ @logificator.singleton_class.include(Logging)
81
+ end
82
+
83
+ describe :logger do
84
+ it 'returns the default logger' do
85
+ logger = Logging::Loggers.default_logger
86
+ expect(logificator.logger).to eq(logger)
87
+ end
88
+
89
+ it 'returns a set logger' do
90
+ logger = new_mock_logger
91
+ logificator.logger = logger
92
+ expect(logificator.logger).to be(logger)
93
+ end
94
+
95
+ it 'returns a logger set via the class method' do
96
+ logger = new_mock_logger
97
+ Logging.logger = logger
98
+ expect(logificator.logger).to be(logger)
99
+ end
100
+ end
101
+
102
+ describe :logger= do
103
+ it 'sets the shared logger via the class method' do
104
+ logger = new_mock_logger
105
+ logificator.logger = logger
106
+ expect(Logging.logger).to be(logger)
107
+ end
108
+
109
+ it 'sets a shared logger accessible via another including class' do
110
+ logger = new_mock_logger
111
+ Object.new.tap do |logificator2|
112
+ logificator2.singleton_class.send(:include, Logging)
113
+ logificator2.logger = logger
114
+ end
115
+ expect(logificator.logger).to be(logger)
116
+ end
117
+
118
+ it 'rejects a non-logger' do
119
+ original_logger = logificator.logger
120
+ expect { logificator.logger = Object.new }.to raise_error(ArgumentError)
121
+ expect(logificator.logger).to be(original_logger)
122
+ end
123
+
124
+ it 'can be reset to default with nil' do
125
+ default_logger = Logging::Loggers.default_logger
126
+ logificator.logger = new_mock_logger
127
+ logificator.logger = nil
128
+ expect(logificator.logger).to eq(default_logger)
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,25 @@
1
+ # ------------------------------------------------------------
2
+ # RSpec
3
+
4
+ require 'spec_helper'
5
+
6
+ # ------------------------------------------------------------
7
+ # RSpec
8
+
9
+ RSpec.configure do |config|
10
+ config.around(:example) do |example|
11
+ next example.run unless defined?(Rails)
12
+
13
+ rails_orig = Object.send(:remove_const, :Rails)
14
+ begin
15
+ example.run
16
+ ensure
17
+ Object.const_set(:Rails, rails_orig)
18
+ end
19
+ end
20
+ end
21
+
22
+ # ------------------------------------------------------------
23
+ # Code under test
24
+
25
+ require 'berkeley_library/logging'
metadata ADDED
@@ -0,0 +1,363 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: berkeley_library-logging
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - David Moles
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-08-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: amazing_print
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: lograge
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.11'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ougai
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: brakeman
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundle-audit
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: ci_reporter_rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: colorize
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
125
+ - !ruby/object:Gem::Dependency
126
+ name: dotenv
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.7'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.7'
139
+ - !ruby/object:Gem::Dependency
140
+ name: irb
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.2'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.2'
153
+ - !ruby/object:Gem::Dependency
154
+ name: listen
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 3.0.5
160
+ - - "<"
161
+ - !ruby/object:Gem::Version
162
+ version: '3.2'
163
+ type: :development
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: 3.0.5
170
+ - - "<"
171
+ - !ruby/object:Gem::Version
172
+ version: '3.2'
173
+ - !ruby/object:Gem::Dependency
174
+ name: rails
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '6.0'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: '6.0'
187
+ - !ruby/object:Gem::Dependency
188
+ name: rake
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - "~>"
192
+ - !ruby/object:Gem::Version
193
+ version: '13.0'
194
+ type: :development
195
+ prerelease: false
196
+ version_requirements: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - "~>"
199
+ - !ruby/object:Gem::Version
200
+ version: '13.0'
201
+ - !ruby/object:Gem::Dependency
202
+ name: rspec-support
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - "~>"
206
+ - !ruby/object:Gem::Version
207
+ version: '3.9'
208
+ type: :development
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - "~>"
213
+ - !ruby/object:Gem::Version
214
+ version: '3.9'
215
+ - !ruby/object:Gem::Dependency
216
+ name: rubocop
217
+ requirement: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - "~>"
220
+ - !ruby/object:Gem::Version
221
+ version: 0.91.0
222
+ type: :development
223
+ prerelease: false
224
+ version_requirements: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - "~>"
227
+ - !ruby/object:Gem::Version
228
+ version: 0.91.0
229
+ - !ruby/object:Gem::Dependency
230
+ name: simplecov
231
+ requirement: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - "~>"
234
+ - !ruby/object:Gem::Version
235
+ version: 0.21.1
236
+ type: :development
237
+ prerelease: false
238
+ version_requirements: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - "~>"
241
+ - !ruby/object:Gem::Version
242
+ version: 0.21.1
243
+ - !ruby/object:Gem::Dependency
244
+ name: simplecov-console
245
+ requirement: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - "~>"
248
+ - !ruby/object:Gem::Version
249
+ version: 0.9.1
250
+ type: :development
251
+ prerelease: false
252
+ version_requirements: !ruby/object:Gem::Requirement
253
+ requirements:
254
+ - - "~>"
255
+ - !ruby/object:Gem::Version
256
+ version: 0.9.1
257
+ - !ruby/object:Gem::Dependency
258
+ name: simplecov-rcov
259
+ requirement: !ruby/object:Gem::Requirement
260
+ requirements:
261
+ - - "~>"
262
+ - !ruby/object:Gem::Version
263
+ version: '0.2'
264
+ type: :development
265
+ prerelease: false
266
+ version_requirements: !ruby/object:Gem::Requirement
267
+ requirements:
268
+ - - "~>"
269
+ - !ruby/object:Gem::Version
270
+ version: '0.2'
271
+ description: A gem providing shared logging code for UC Berkeley Library gems and
272
+ Rails applications
273
+ email: dmoles@berkeley.edu
274
+ executables: []
275
+ extensions: []
276
+ extra_rdoc_files: []
277
+ files:
278
+ - ".gitignore"
279
+ - ".idea/inspectionProfiles/Project_Default.xml"
280
+ - ".idea/logging.iml"
281
+ - ".idea/modules.xml"
282
+ - ".idea/vcs.xml"
283
+ - ".rubocop.yml"
284
+ - ".ruby-version"
285
+ - ".simplecov"
286
+ - ".travis.yml"
287
+ - CHANGES.md
288
+ - Dockerfile
289
+ - Gemfile
290
+ - Jenkinsfile
291
+ - LICENSE.md
292
+ - README.md
293
+ - Rakefile
294
+ - berkeley_library-logging.gemspec
295
+ - docker-compose.yml
296
+ - lib/berkeley_library/logging.rb
297
+ - lib/berkeley_library/logging/configurator.rb
298
+ - lib/berkeley_library/logging/env.rb
299
+ - lib/berkeley_library/logging/events.rb
300
+ - lib/berkeley_library/logging/formatters.rb
301
+ - lib/berkeley_library/logging/logger.rb
302
+ - lib/berkeley_library/logging/loggers.rb
303
+ - lib/berkeley_library/logging/module_info.rb
304
+ - lib/berkeley_library/logging/railtie.rb
305
+ - lib/berkeley_library/logging/tagged_logging_extensions.rb
306
+ - rakelib/.rubocop.yml
307
+ - rakelib/bundle.rake
308
+ - rakelib/coverage.rake
309
+ - rakelib/gem.rake
310
+ - rakelib/rubocop.rake
311
+ - rakelib/spec.rake
312
+ - spec/.rubocop.yml
313
+ - spec/rails/ucblit/logging/configurator_spec.rb
314
+ - spec/rails/ucblit/logging/env_spec.rb
315
+ - spec/rails/ucblit/logging/formatters_spec.rb
316
+ - spec/rails/ucblit/logging/loggers_spec.rb
317
+ - spec/rails/ucblit/logging/railtie_spec.rb
318
+ - spec/rails/ucblit/logging_spec.rb
319
+ - spec/rails_helper.rb
320
+ - spec/spec_helper.rb
321
+ - spec/standalone/ucblit/logging/configurator_spec.rb
322
+ - spec/standalone/ucblit/logging/formatters_spec.rb
323
+ - spec/standalone/ucblit/logging/loggers_spec.rb
324
+ - spec/standalone/ucblit/logging_spec.rb
325
+ - spec/standalone_helper.rb
326
+ homepage: https://github.com/BerkeleyLibrary/logging
327
+ licenses:
328
+ - MIT
329
+ metadata: {}
330
+ post_install_message:
331
+ rdoc_options: []
332
+ require_paths:
333
+ - lib
334
+ required_ruby_version: !ruby/object:Gem::Requirement
335
+ requirements:
336
+ - - ">="
337
+ - !ruby/object:Gem::Version
338
+ version: '2.7'
339
+ required_rubygems_version: !ruby/object:Gem::Requirement
340
+ requirements:
341
+ - - ">="
342
+ - !ruby/object:Gem::Version
343
+ version: '0'
344
+ requirements: []
345
+ rubygems_version: 3.1.4
346
+ signing_key:
347
+ specification_version: 4
348
+ summary: Opinionated Ruby/Rails logging for UC Berkeley Library
349
+ test_files:
350
+ - spec/.rubocop.yml
351
+ - spec/rails/ucblit/logging/configurator_spec.rb
352
+ - spec/rails/ucblit/logging/env_spec.rb
353
+ - spec/rails/ucblit/logging/formatters_spec.rb
354
+ - spec/rails/ucblit/logging/loggers_spec.rb
355
+ - spec/rails/ucblit/logging/railtie_spec.rb
356
+ - spec/rails/ucblit/logging_spec.rb
357
+ - spec/rails_helper.rb
358
+ - spec/spec_helper.rb
359
+ - spec/standalone/ucblit/logging/configurator_spec.rb
360
+ - spec/standalone/ucblit/logging/formatters_spec.rb
361
+ - spec/standalone/ucblit/logging/loggers_spec.rb
362
+ - spec/standalone/ucblit/logging_spec.rb
363
+ - spec/standalone_helper.rb