berkeley_library-logging 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/logging.iml" filepath="$PROJECT_DIR$/.idea/logging.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.rubocop.yml ADDED
@@ -0,0 +1,271 @@
1
+ AllCops:
2
+ # Exclude generated files
3
+ Exclude:
4
+ - 'bin/**/*'
5
+ - 'node_modules/**/*'
6
+ - 'artifacts/**/*'
7
+
8
+ # Allow one line around block body (Layout/EmptyLines will still disallow two or more)
9
+ Layout/EmptyLinesAroundBlockBody:
10
+ Enabled: false
11
+
12
+ # Allow one line around class body (Layout/EmptyLines will still disallow two or more)
13
+ Layout/EmptyLinesAroundClassBody:
14
+ Enabled: false
15
+
16
+ # Allow one line around module body (Layout/EmptyLines will still disallow two or more)
17
+ Layout/EmptyLinesAroundModuleBody:
18
+ Enabled: false
19
+
20
+ # Reasonable line-length check; it's too easy for the cure to be worse than the disease
21
+ Layout/LineLength:
22
+ Max: 150
23
+
24
+ # Make indents consistent regardless of the lengths of variables and method names and whatnot
25
+ Layout/MultilineMethodCallIndentation:
26
+ EnforcedStyle: indented
27
+
28
+ # Produces monsters
29
+ Layout/MultilineOperationIndentation:
30
+ Enabled: false
31
+
32
+ # We meant to do that
33
+ Naming/MemoizedInstanceVariableName:
34
+ Enabled: False
35
+
36
+ # It works in context, trust us
37
+ Naming/MethodParameterName:
38
+ Enabled: False
39
+
40
+ # Confusing and weird
41
+ Naming/VariableNumber:
42
+ Enabled: False
43
+
44
+ # Do what's readable in the context you're in
45
+ Style/AccessModifierDeclarations:
46
+ Enabled: false
47
+
48
+ # 👎 to cultural imperialism
49
+ Style/AsciiComments:
50
+ Enabled: false
51
+
52
+ # Seriously?
53
+ Style/CommentedKeyword:
54
+ Enabled: False
55
+
56
+ # Disable problematic module documentation check (see https://github.com/bbatsov/rubocop/issues/947)
57
+ Style/Documentation:
58
+ Enabled: false
59
+
60
+ # Adding more line noise to format strings will not improve them
61
+ Style/FormatStringToken:
62
+ Enabled: false
63
+
64
+ # Putting '# frozen_string_literal: true' everywhere does not make the world a better place
65
+ Style/FrozenStringLiteralComment:
66
+ Enabled: false
67
+
68
+ # Requiring the lambda() method just makes wordy calls wordier
69
+ Style/Lambda:
70
+ EnforcedStyle: literal
71
+
72
+ # `foo.positive?` is cute, but it's not actually more readable than `foo > 0`
73
+ Style/NumericPredicate:
74
+ Enabled: false
75
+
76
+ # Don't be unnecessarily redundant
77
+ Style/ReturnNil:
78
+ Enabled: true
79
+ EnforcedStyle: return
80
+
81
+ # Unclear why it's a good idea to give parameters semantically meaningless names
82
+ Style/SingleLineBlockParams:
83
+ Enabled: false
84
+
85
+ # The semantics of `foo&.bar` are a lot less interchangeable with `foo && foo.bar` than RuboCop thinks
86
+ Style/SafeNavigation:
87
+ Enabled: false
88
+
89
+ ############################################################
90
+ # Added in RuboCop 0.80
91
+
92
+ Style/HashEachMethods:
93
+ Enabled: true
94
+
95
+ Style/HashTransformKeys:
96
+ Enabled: true
97
+
98
+ Style/HashTransformValues:
99
+ Enabled: true
100
+
101
+ ############################################################
102
+ # Added in RuboCop 0.81
103
+
104
+ Lint/StructNewOverride:
105
+ Enabled: true
106
+
107
+ Lint/RaiseException:
108
+ Enabled: true
109
+
110
+ ############################################################
111
+ # Added in RuboCop 0.82
112
+
113
+ Layout/SpaceAroundMethodCallOperator:
114
+ Enabled: true
115
+
116
+ Style/ExponentialNotation:
117
+ Enabled: false
118
+
119
+ ############################################################
120
+ # Added in RuboCop 0.83
121
+
122
+ Layout/EmptyLinesAroundAttributeAccessor:
123
+ Enabled: true
124
+
125
+ Style/SlicingWithRange:
126
+ Enabled: true
127
+
128
+ ############################################################
129
+ # Added in RuboCop 0.84
130
+
131
+ Lint/DeprecatedOpenSSLConstant:
132
+ Enabled: true
133
+
134
+ ############################################################
135
+ # Added in RuboCop 0.85
136
+
137
+ Lint/MixedRegexpCaptureTypes:
138
+ Enabled: true
139
+
140
+ Style/RedundantRegexpEscape:
141
+ Enabled: true
142
+
143
+ Style/RedundantRegexpCharacterClass:
144
+ Enabled: true
145
+
146
+ ############################################################
147
+ # Added in Rubocop 0.86
148
+
149
+ Style/RedundantFetchBlock:
150
+ Enabled: true
151
+
152
+ ############################################################
153
+ # Added in Rubocop 0.87
154
+
155
+ # Sometimes we separate things for a reason
156
+ Style/AccessorGrouping:
157
+ Enabled: false
158
+
159
+ Style/BisectedAttrAccessor:
160
+ Enabled: true
161
+
162
+ Style/RedundantAssignment:
163
+ Enabled: true
164
+
165
+ ############################################################
166
+ # Added in Rubocop 0.88
167
+
168
+ Lint/DuplicateElsifCondition:
169
+ Enabled: true
170
+
171
+ Style/ArrayCoercion:
172
+ Enabled: true
173
+
174
+ Style/CaseLikeIf:
175
+ Enabled: true
176
+
177
+ Style/HashAsLastArrayItem:
178
+ Enabled: true
179
+
180
+ Style/HashLikeCase:
181
+ Enabled: true
182
+
183
+ Style/RedundantFileExtensionInRequire:
184
+ Enabled: true
185
+
186
+ ############################################################
187
+ # Added in Rubocop 0.89
188
+
189
+ Lint/BinaryOperatorWithIdenticalOperands:
190
+ Enabled: true
191
+
192
+ Lint/DuplicateRescueException:
193
+ Enabled: true
194
+
195
+ Lint/EmptyConditionalBody:
196
+ Enabled: true
197
+
198
+ Lint/FloatComparison:
199
+ Enabled: true
200
+
201
+ Lint/MissingSuper:
202
+ Enabled: true
203
+
204
+ Lint/OutOfRangeRegexpRef:
205
+ Enabled: true
206
+
207
+ Lint/SelfAssignment:
208
+ Enabled: true
209
+
210
+ Lint/TopLevelReturnWithArgument:
211
+ Enabled: true
212
+
213
+ Lint/UnreachableLoop:
214
+ Enabled: true
215
+
216
+ Style/ExplicitBlockArgument:
217
+ Enabled: true
218
+
219
+ Style/GlobalStdStream:
220
+ Enabled: true
221
+
222
+ Style/OptionalBooleanParameter:
223
+ Enabled: true
224
+
225
+ Style/SingleArgumentDig:
226
+ Enabled: true
227
+
228
+ Style/SoleNestedConditional:
229
+ Enabled: true
230
+
231
+ Style/StringConcatenation:
232
+ Enabled: true
233
+
234
+ ############################################################
235
+ # Added in Rubocop 0.90
236
+
237
+ Lint/DuplicateRequire:
238
+ Enabled: true
239
+
240
+ Lint/EmptyFile:
241
+ Enabled: true
242
+
243
+ Lint/TrailingCommaInAttributeDeclaration:
244
+ Enabled: true
245
+
246
+ Lint/UselessMethodDefinition:
247
+ Enabled: true
248
+
249
+ Style/CombinableLoops:
250
+ Enabled: true
251
+
252
+ Style/KeywordParametersOrder:
253
+ Enabled: true
254
+
255
+ Style/RedundantSelfAssignment:
256
+ Enabled: true
257
+
258
+ ############################################################
259
+ # Added in Rubocop 0.91
260
+
261
+ Layout/BeginEndAlignment:
262
+ Enabled: true
263
+
264
+ Lint/ConstantDefinitionInBlock:
265
+ Enabled: true
266
+
267
+ Lint/IdentityComparison:
268
+ Enabled: true
269
+
270
+ Lint/UselessTimes:
271
+ Enabled: true
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7
data/.simplecov ADDED
@@ -0,0 +1,4 @@
1
+ SimpleCov.start 'rails' do
2
+ add_filter 'module_info.rb'
3
+ formatter SimpleCov::Formatter::SimpleFormatter
4
+ end
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+
3
+ os:
4
+ - linux
5
+ - osx
6
+
7
+ rvm:
8
+ - 2.7
9
+ - ruby-head
data/CHANGES.md ADDED
@@ -0,0 +1,12 @@
1
+ # 0.2.0 (2021-08-18)
2
+
3
+ - Rename to `BerkeleyLibrary::Logging` in prep for move to GitHub
4
+
5
+ # 0.1.1 (2021-05-03)
6
+
7
+ - Adds a global logger accessible by including `UCBLIT::Logging`, or via class methods
8
+ on that module.
9
+
10
+ # 0.1.0 (2021-03-12)
11
+
12
+ - Initial pseudo-release.
data/Dockerfile ADDED
@@ -0,0 +1,57 @@
1
+ # =============================================================================
2
+ # Target: base
3
+
4
+ FROM ruby:2.7-alpine AS base
5
+
6
+ RUN apk --no-cache --update upgrade && \
7
+ apk --no-cache add \
8
+ bash \
9
+ ca-certificates \
10
+ git \
11
+ libc6-compat \
12
+ openssl \
13
+ tzdata \
14
+ xz-libs \
15
+ && rm -rf /var/cache/apk/*
16
+
17
+ WORKDIR /opt/app
18
+
19
+ # =============================================================================
20
+ # Target: development
21
+ #
22
+
23
+ FROM base AS development
24
+
25
+ # Install system packages needed to build gems with C extensions.
26
+ RUN apk --update --no-cache add \
27
+ build-base \
28
+ coreutils \
29
+ git \
30
+ && rm -rf /var/cache/apk/*
31
+
32
+ # The base image ships bundler 1.17.2, but we want something more recent
33
+ RUN gem install bundler -v 2.1.4
34
+
35
+ # Copy codebase to WORKDIR. Unlike application projects, for a gem project
36
+ # we need to do this before running `bundle install`, in order for the gem
37
+ # we're building to be able to "install" itself.
38
+ COPY . .
39
+
40
+ # Install gems.
41
+ RUN bundle install --path=/usr/local/bundle
42
+
43
+ # =============================================================================
44
+ # Target: production
45
+
46
+ FROM base AS production
47
+
48
+ # Copy the built codebase from the dev stage
49
+ COPY --from=development /opt/app /opt/app
50
+ COPY --from=development /usr/local/bundle /usr/local/bundle
51
+
52
+ # Sanity-check that everything was installed correctly and still runs in the
53
+ # slimmed-down production image.
54
+ RUN bundle config set deployment 'true'
55
+ RUN bundle install --local --path=/usr/local/bundle
56
+
57
+ CMD ['bundle', 'exec', 'rake']
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Jenkinsfile ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env groovy
2
+
3
+ dockerComposePipeline(
4
+ commands: [
5
+ 'bundle exec rake coverage',
6
+ 'bundle exec rake rubocop',
7
+ 'bundle exec rake bundle:audit',
8
+ 'bundle exec rake gem'
9
+ ],
10
+ artifacts: [
11
+ junit: 'artifacts/rspec/**/*.xml',
12
+ html : [
13
+ 'Code Coverage': 'artifacts/rcov',
14
+ 'RuboCop' : 'artifacts/rubocop'
15
+ ],
16
+ raw : [
17
+ 'artifacts/**/*.gem',
18
+ 'artifacts/**/*.json'
19
+ ]
20
+ ]
21
+ )
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ # The MIT License (MIT)
2
+
3
+ Copyright © 2020 The Regents of the University of California
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a
6
+ copy of this software and associated documentation files (the “Software”),
7
+ to deal in the Software without restriction, including without limitation
8
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
+ and/or sell copies of the Software, and to permit persons to whom the
10
+ Software is furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # BerkeleyLibrary::Logging
2
+
3
+ [![Build Status](https://travis-ci.com/BerkeleyLibrary/logging.svg?branch=main)](https://travis-ci.com/github/BerkeleyLibrary/logging/)
4
+ [![Gem Version](https://img.shields.io/gem/v/berkeley_library-logging.svg)](https://github.com/BerkeleyLibrary/logging/releases)
5
+
6
+ Opinionated logging for UCB Library IT Rails applications.
7
+
8
+ ## Usage
9
+
10
+ ### With Rails
11
+
12
+ `BerkeleyLibrary::Logging` is implemented as a Railtie, so adding it to your Gemfile should
13
+ cause it to be loaded automatically.
14
+
15
+ ### With or without Rails
16
+
17
+ You can load `BerkeleyLibrary::Logging` explicitly with `require`:
18
+
19
+ ```ruby
20
+ require 'berkeley_library/logging'
21
+
22
+ logger = BerkeleyLibrary::Logging::Logger.default_logger
23
+ ```
24
+
25
+ In a Rails environment, this will return the Rails logger (already configured by the
26
+ Railtie); in a non-Rails environment, it will return a default, human-readable STDOUT
27
+ logger.
28
+
29
+ Alternatively, you can create a logger directly:
30
+
31
+ ```ruby
32
+ require 'berkeley_library/logging'
33
+
34
+ logger = BerkeleyLibrary::Logging::Loggers.new_readable_logger('/tmp/mylog.log')
35
+ logger.warn('oops')
36
+ puts File.read('/tmp/mylog.log')
37
+
38
+ # => # Logfile created on 2021-02-03 16:47:06 -0800 by logger.rb/v1.4.2
39
+ [2021-02-03T16:47:10.506-08:00] WARN: oops
40
+
41
+ logger = BerkeleyLibrary::Logging::Loggers.new_json_logger('/tmp/mylog.json')
42
+ logger.warn('oops')
43
+ puts File.read('/tmp/mylog.log')
44
+
45
+ # => # Logfile created on 2021-02-03 16:49:30 -0800 by logger.rb/v1.4.2
46
+ {"name":"irb","hostname":"test.example.org","pid":7080,"level":40,"time":"2021-02-03T16:49:34.842-08:00","v":0,"severity":"WARN","msg":"oops"}
47
+ ```