lamian 1.1.0 → 1.5.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
- SHA1:
3
- metadata.gz: 5fed5c60bd57fa0cd1e33f57ee3ffebd8009ee7c
4
- data.tar.gz: 6c6324fa43333c990e1562e0a8cb2e63f7871496
2
+ SHA256:
3
+ metadata.gz: d658a3a17f04025bed6140c233857a95f2e153332654d3fe6fbc2c10d0ef7916
4
+ data.tar.gz: 2b73f21507f4fa1e2a18ec20bfe57d613abbee01b079ed1fc78f12f966623854
5
5
  SHA512:
6
- metadata.gz: e3b733bccc6a50fadefe5eac089eead5fa764a3dff4b3363049f5ad773d9f970a19b5e5e0395741ad3cd5bf8c6a7f6b01d583c9fa6d987fb4dce68c019c0034e
7
- data.tar.gz: 6e966db934eee4fafe40ffb69c155dafb8b9f3d6ad15d53346b12b4c26a149ab1751d6bb23cfd2fd6317d05f81e3d787f965209f18bd0388771965307e8305f4
6
+ metadata.gz: 1a8d7a403f777a0e2ddf846d7da980267d22b5d44665aed8e4794c851d5a92ce535a1e6e338cd100c4d1fe81eaa13290857ce4d44bddd557172aebd8803f1a23
7
+ data.tar.gz: c7b32c823fc0972a0039f4a2618671d8db045680b6b5b5158ba70c88bc06715b8fe0b431820cca705f0b28ebbc107171c097498da95d67ffa5814a9b8e2ca219
@@ -0,0 +1,56 @@
1
+ name: Test
2
+
3
+ on: [push, pull_request]
4
+
5
+ env:
6
+ FULL_COVERAGE_CHECK: true
7
+
8
+ jobs:
9
+ full-check:
10
+ runs-on: ubuntu-latest
11
+
12
+ # We want to run on external PRs, but not on our own internal PRs as they'll be run on push event
13
+ if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'umbrellio/lamian'
14
+
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: 3
20
+ bundler-cache: true
21
+ - name: Run Linter
22
+ run: bundle exec ci-helper RubocopLint
23
+ - name: Check missed spec suffixes
24
+ run: bundle exec ci-helper CheckSpecSuffixes --extra-paths spec/*.rb --ignored-paths spec/*_helper.rb
25
+ - name: Run specs
26
+ run: bundle exec ci-helper RunSpecs
27
+ - name: Audit
28
+ run: bundle exec ci-helper BundlerAudit
29
+ - name: Documentation coverage
30
+ run: bundle exec rake doc:coverage
31
+ - name: Coveralls
32
+ uses: coverallsapp/github-action@master
33
+ with:
34
+ github-token: ${{ secrets.GITHUB_TOKEN }}
35
+ specs:
36
+ runs-on: ubuntu-latest
37
+
38
+ env:
39
+ FULL_COVERAGE_CHECK: false
40
+
41
+ # We want to run on external PRs, but not on our own internal PRs as they'll be run on push event
42
+ if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'umbrellio/lamian'
43
+
44
+ strategy:
45
+ fail-fast: false
46
+ matrix:
47
+ ruby: [2.6, 2.7]
48
+
49
+ steps:
50
+ - uses: actions/checkout@v2
51
+ - uses: ruby/setup-ruby@v1
52
+ with:
53
+ ruby-version: ${{ matrix.ruby }}
54
+ bundler-cache: true
55
+ - name: Run specs
56
+ run: bundle exec ci-helper RunSpecs
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /.ruby-version
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ inherit_gem:
2
+ rubocop-config-umbrellio: lib/rubocop.yml
3
+
4
+ AllCops:
5
+ DisplayCopNames: true
6
+ TargetRubyVersion: 2.5
7
+
8
+ RSpec/EmptyLineAfterHook:
9
+ Enabled: false
10
+
11
+ Style/HashConversion:
12
+ Exclude:
13
+ - spec/**/*_spec.rb
data/Changelog.md ADDED
@@ -0,0 +1,55 @@
1
+ # Lamian version changes (since 0.1.0)
2
+
3
+ Update this on a pull request, under `Lamian::VERSION`
4
+ (also known as next version). If this constant would be changed without release,
5
+ I'll update it here too
6
+
7
+ ## 1.3.0
8
+ * Add support for the (new sentry gem)[https://github.com/getsentry/sentry-ruby].
9
+
10
+ ## 1.2.0
11
+ * Add `raven_log_size_limit` config option for limiting amount of data sent to sentry (defaults to `500_000`)
12
+
13
+ ## 1.1.0
14
+ * Add support for sentry and sidekiq
15
+
16
+ ## 1.0.0
17
+
18
+ * `6d8fee8` fixed a bug when ::Logger#log was not prepended. `::Logger#log` is an alias for `::Logger#add`,
19
+ which ruins concept of single entry point :(. Also tied it to lamian instance
20
+
21
+ ## 0.3.3
22
+
23
+ * `8136689` fixed crashes when dump used outside lamian context
24
+
25
+
26
+ ## 0.3.2
27
+
28
+ * `e57e6cec` Changed rails dependency from `~> 4.2` to `>= 4.2`
29
+
30
+
31
+ ## 0.3.1
32
+
33
+ * 34ca83b5 Fixed formatting
34
+
35
+ Stabilized formatting api, which removes control sequences from loggers data.
36
+ E.g. `"[23mNice, lol[0m\n"` becomes `"Nice, lol\n"`
37
+
38
+
39
+ ## 0.3.0
40
+
41
+ * `d24f895b` API update
42
+
43
+ Updated API, so lamian is now forced to be used with block.
44
+ It also simplified usage outside a middleware
45
+
46
+
47
+ ## 0.2.0
48
+ * `3166517e` Added integrtation with rails
49
+
50
+ Injected middleware before `ExceptionNotification`, so `ExceptionNotification`
51
+ can use current log without any configuration. Also added some views
52
+
53
+
54
+ ## 0.1.0
55
+ * `62eb8685` Made test version to check it's integration with rails application
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in lamian.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,278 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lamian (1.5.0)
5
+ rails (>= 4.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (6.1.4.1)
11
+ actionpack (= 6.1.4.1)
12
+ activesupport (= 6.1.4.1)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ actionmailbox (6.1.4.1)
16
+ actionpack (= 6.1.4.1)
17
+ activejob (= 6.1.4.1)
18
+ activerecord (= 6.1.4.1)
19
+ activestorage (= 6.1.4.1)
20
+ activesupport (= 6.1.4.1)
21
+ mail (>= 2.7.1)
22
+ actionmailer (6.1.4.1)
23
+ actionpack (= 6.1.4.1)
24
+ actionview (= 6.1.4.1)
25
+ activejob (= 6.1.4.1)
26
+ activesupport (= 6.1.4.1)
27
+ mail (~> 2.5, >= 2.5.4)
28
+ rails-dom-testing (~> 2.0)
29
+ actionpack (6.1.4.1)
30
+ actionview (= 6.1.4.1)
31
+ activesupport (= 6.1.4.1)
32
+ rack (~> 2.0, >= 2.0.9)
33
+ rack-test (>= 0.6.3)
34
+ rails-dom-testing (~> 2.0)
35
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
36
+ actiontext (6.1.4.1)
37
+ actionpack (= 6.1.4.1)
38
+ activerecord (= 6.1.4.1)
39
+ activestorage (= 6.1.4.1)
40
+ activesupport (= 6.1.4.1)
41
+ nokogiri (>= 1.8.5)
42
+ actionview (6.1.4.1)
43
+ activesupport (= 6.1.4.1)
44
+ builder (~> 3.1)
45
+ erubi (~> 1.4)
46
+ rails-dom-testing (~> 2.0)
47
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
48
+ activejob (6.1.4.1)
49
+ activesupport (= 6.1.4.1)
50
+ globalid (>= 0.3.6)
51
+ activemodel (6.1.4.1)
52
+ activesupport (= 6.1.4.1)
53
+ activerecord (6.1.4.1)
54
+ activemodel (= 6.1.4.1)
55
+ activesupport (= 6.1.4.1)
56
+ activestorage (6.1.4.1)
57
+ actionpack (= 6.1.4.1)
58
+ activejob (= 6.1.4.1)
59
+ activerecord (= 6.1.4.1)
60
+ activesupport (= 6.1.4.1)
61
+ marcel (~> 1.0.0)
62
+ mini_mime (>= 1.1.0)
63
+ activesupport (6.1.4.1)
64
+ concurrent-ruby (~> 1.0, >= 1.0.2)
65
+ i18n (>= 1.6, < 2)
66
+ minitest (>= 5.1)
67
+ tzinfo (~> 2.0)
68
+ zeitwerk (~> 2.3)
69
+ addressable (2.8.0)
70
+ public_suffix (>= 2.0.2, < 5.0)
71
+ ast (2.4.2)
72
+ builder (3.2.4)
73
+ bundler-audit (0.9.0.1)
74
+ bundler (>= 1.2.0, < 3)
75
+ thor (~> 1.0)
76
+ ci-helper (0.4.2)
77
+ colorize (~> 0.8)
78
+ dry-inflector (~> 0.2)
79
+ umbrellio-sequel-plugins (~> 0.4)
80
+ coderay (1.1.3)
81
+ colorize (0.8.1)
82
+ concurrent-ruby (1.1.9)
83
+ crass (1.0.6)
84
+ diff-lcs (1.4.4)
85
+ docile (1.4.0)
86
+ dry-inflector (0.2.1)
87
+ erubi (1.10.0)
88
+ faraday (1.8.0)
89
+ faraday-em_http (~> 1.0)
90
+ faraday-em_synchrony (~> 1.0)
91
+ faraday-excon (~> 1.1)
92
+ faraday-httpclient (~> 1.0.1)
93
+ faraday-net_http (~> 1.0)
94
+ faraday-net_http_persistent (~> 1.1)
95
+ faraday-patron (~> 1.0)
96
+ faraday-rack (~> 1.0)
97
+ multipart-post (>= 1.2, < 3)
98
+ ruby2_keywords (>= 0.0.4)
99
+ faraday-em_http (1.0.0)
100
+ faraday-em_synchrony (1.0.0)
101
+ faraday-excon (1.1.0)
102
+ faraday-httpclient (1.0.1)
103
+ faraday-net_http (1.0.1)
104
+ faraday-net_http_persistent (1.2.0)
105
+ faraday-patron (1.0.0)
106
+ faraday-rack (1.0.0)
107
+ globalid (0.5.2)
108
+ activesupport (>= 5.0)
109
+ i18n (1.8.11)
110
+ concurrent-ruby (~> 1.0)
111
+ launchy (2.5.0)
112
+ addressable (~> 2.7)
113
+ loofah (2.12.0)
114
+ crass (~> 1.0.2)
115
+ nokogiri (>= 1.5.9)
116
+ mail (2.7.1)
117
+ mini_mime (>= 0.1.1)
118
+ marcel (1.0.2)
119
+ method_source (1.0.0)
120
+ mini_mime (1.1.2)
121
+ minitest (5.14.4)
122
+ multipart-post (2.1.1)
123
+ nio4r (2.5.8)
124
+ nokogiri (1.12.5-x86_64-darwin)
125
+ racc (~> 1.4)
126
+ nokogiri (1.12.5-x86_64-linux)
127
+ racc (~> 1.4)
128
+ parallel (1.21.0)
129
+ parser (3.0.2.0)
130
+ ast (~> 2.4.1)
131
+ pry (0.14.1)
132
+ coderay (~> 1.1)
133
+ method_source (~> 1.0)
134
+ public_suffix (4.0.6)
135
+ racc (1.6.0)
136
+ rack (2.2.3)
137
+ rack-test (1.1.0)
138
+ rack (>= 1.0, < 3)
139
+ rails (6.1.4.1)
140
+ actioncable (= 6.1.4.1)
141
+ actionmailbox (= 6.1.4.1)
142
+ actionmailer (= 6.1.4.1)
143
+ actionpack (= 6.1.4.1)
144
+ actiontext (= 6.1.4.1)
145
+ actionview (= 6.1.4.1)
146
+ activejob (= 6.1.4.1)
147
+ activemodel (= 6.1.4.1)
148
+ activerecord (= 6.1.4.1)
149
+ activestorage (= 6.1.4.1)
150
+ activesupport (= 6.1.4.1)
151
+ bundler (>= 1.15.0)
152
+ railties (= 6.1.4.1)
153
+ sprockets-rails (>= 2.0.0)
154
+ rails-dom-testing (2.0.3)
155
+ activesupport (>= 4.2.0)
156
+ nokogiri (>= 1.6)
157
+ rails-html-sanitizer (1.4.2)
158
+ loofah (~> 2.3)
159
+ railties (6.1.4.1)
160
+ actionpack (= 6.1.4.1)
161
+ activesupport (= 6.1.4.1)
162
+ method_source
163
+ rake (>= 0.13)
164
+ thor (~> 1.0)
165
+ rainbow (3.0.0)
166
+ rake (13.0.6)
167
+ regexp_parser (2.1.1)
168
+ rexml (3.2.5)
169
+ rspec (3.10.0)
170
+ rspec-core (~> 3.10.0)
171
+ rspec-expectations (~> 3.10.0)
172
+ rspec-mocks (~> 3.10.0)
173
+ rspec-core (3.10.1)
174
+ rspec-support (~> 3.10.0)
175
+ rspec-expectations (3.10.1)
176
+ diff-lcs (>= 1.2.0, < 2.0)
177
+ rspec-support (~> 3.10.0)
178
+ rspec-mocks (3.10.2)
179
+ diff-lcs (>= 1.2.0, < 2.0)
180
+ rspec-support (~> 3.10.0)
181
+ rspec-support (3.10.2)
182
+ rubocop (1.17.0)
183
+ parallel (~> 1.10)
184
+ parser (>= 3.0.0.0)
185
+ rainbow (>= 2.2.2, < 4.0)
186
+ regexp_parser (>= 1.8, < 3.0)
187
+ rexml
188
+ rubocop-ast (>= 1.7.0, < 2.0)
189
+ ruby-progressbar (~> 1.7)
190
+ unicode-display_width (>= 1.4.0, < 3.0)
191
+ rubocop-ast (1.12.0)
192
+ parser (>= 3.0.1.1)
193
+ rubocop-config-umbrellio (1.17.0.53)
194
+ rubocop (= 1.17.0)
195
+ rubocop-performance (= 1.10.0)
196
+ rubocop-rails (= 2.9.1)
197
+ rubocop-rake (= 0.5.1)
198
+ rubocop-rspec (= 2.2.0)
199
+ rubocop-sequel (= 0.2.0)
200
+ rubocop-performance (1.10.0)
201
+ rubocop (>= 0.90.0, < 2.0)
202
+ rubocop-ast (>= 0.4.0)
203
+ rubocop-rails (2.9.1)
204
+ activesupport (>= 4.2.0)
205
+ rack (>= 1.1)
206
+ rubocop (>= 0.90.0, < 2.0)
207
+ rubocop-rake (0.5.1)
208
+ rubocop
209
+ rubocop-rspec (2.2.0)
210
+ rubocop (~> 1.0)
211
+ rubocop-ast (>= 1.1.0)
212
+ rubocop-sequel (0.2.0)
213
+ rubocop (~> 1.0)
214
+ ruby-progressbar (1.11.0)
215
+ ruby2_keywords (0.0.5)
216
+ semantic_logger (4.8.2)
217
+ concurrent-ruby (~> 1.0)
218
+ sentry-raven (3.1.2)
219
+ faraday (>= 1.0)
220
+ sentry-ruby (4.7.3)
221
+ concurrent-ruby (~> 1.0, >= 1.0.2)
222
+ faraday (>= 1.0)
223
+ sentry-ruby-core (= 4.7.3)
224
+ sentry-ruby-core (4.7.3)
225
+ concurrent-ruby
226
+ faraday
227
+ sequel (5.50.0)
228
+ simplecov (0.21.2)
229
+ docile (~> 1.1)
230
+ simplecov-html (~> 0.11)
231
+ simplecov_json_formatter (~> 0.1)
232
+ simplecov-html (0.12.3)
233
+ simplecov-lcov (0.8.0)
234
+ simplecov_json_formatter (0.1.3)
235
+ sprockets (4.0.2)
236
+ concurrent-ruby (~> 1.0)
237
+ rack (> 1, < 3)
238
+ sprockets-rails (3.4.0)
239
+ actionpack (>= 5.2)
240
+ activesupport (>= 5.2)
241
+ sprockets (>= 3.0.0)
242
+ symbiont-ruby (0.7.0)
243
+ thor (1.1.0)
244
+ tzinfo (2.0.4)
245
+ concurrent-ruby (~> 1.0)
246
+ umbrellio-sequel-plugins (0.5.1.27)
247
+ sequel
248
+ symbiont-ruby
249
+ unicode-display_width (2.1.0)
250
+ websocket-driver (0.7.5)
251
+ websocket-extensions (>= 0.1.0)
252
+ websocket-extensions (0.1.5)
253
+ yard (0.9.26)
254
+ zeitwerk (2.5.1)
255
+
256
+ PLATFORMS
257
+ x86_64-darwin-19
258
+ x86_64-darwin-20
259
+ x86_64-linux
260
+
261
+ DEPENDENCIES
262
+ bundler-audit
263
+ ci-helper
264
+ lamian!
265
+ launchy
266
+ pry
267
+ rake
268
+ rspec
269
+ rubocop-config-umbrellio
270
+ semantic_logger
271
+ sentry-raven
272
+ sentry-ruby
273
+ simplecov
274
+ simplecov-lcov
275
+ yard
276
+
277
+ BUNDLED WITH
278
+ 2.2.30
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 JelF, Umbrellio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ 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 FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # Lamian
2
+ [![Actions Status](https://github.com/umbrellio/lamian/workflows/Test/badge.svg)](https://github.com/umbrellio/lamian/actions) [![Coverage Status](https://coveralls.io/repos/github/umbrellio/lamian/badge.svg?branch=master)](https://coveralls.io/github/umbrellio/lamian?branch=master) [![Gem Version](https://badge.fury.io/rb/lamian.svg)](https://badge.fury.io/rb/lamian)
3
+
4
+
5
+ Lamian is an in-memory logger, which content could be released for error messages.
6
+ It is designed to work in pair with `exception_notification` gem inside rails
7
+ aplications
8
+
9
+ ## Usage with ExceptionNotification
10
+
11
+ 1. Add `gem 'lamian'` into your Gemfile
12
+ 2. Extend `Rails.logger` and any other loggers you want to mirror by
13
+ `Lamian::LoggerExtension`: `Lamian.extend_logger(logger)`
14
+ 3. Add 'request_log' section inside your `ExceptionNotification.configure`
15
+ (see [ExceptionNotification README](https://github.com/smartinez87/exception_notification/blob/master/README.md))
16
+ 4. ExceptionNotification's messages would have 'Request Log' section
17
+
18
+ ## Extended Usage
19
+
20
+ Add a 'request_log' section into ExceptionNotification's background section.
21
+ Add `Lamian.run { }` around code with logs you want to collect. Note, that
22
+ logs would be accessible only inside this section and removed after section end.
23
+
24
+ ## Sentry (sentry-ruby)
25
+
26
+ ### Usage
27
+
28
+ It automatically redefines `Sentry.configuration.before_send` callback
29
+ if Sentry initialization is completed. If `before_send` is already defined
30
+ it wraps custom callback.
31
+
32
+ ### Usage with Sidekiq
33
+
34
+ You should add Lamian middleware to the Sidekiq initializer like this:
35
+
36
+ ```ruby
37
+ config.server_middleware do |chain|
38
+ chain.prepend(Lamian::SidekiqSentryMiddleware)
39
+ end
40
+ ```
41
+
42
+ ### Usage with SemanticLogger
43
+
44
+ You should add Lamian appender to the SematicLogger appenders like this:
45
+
46
+ ```ruby
47
+ SemanticLogger.add_appender(appender: Lamian::SemanticLoggerAppender.new)
48
+ ```
49
+
50
+ ### Patching Sentry Scope
51
+
52
+ If you want to send events asynchronously you need to patch `Sentry::Scope`.
53
+
54
+ ```ruby
55
+ # Somewhere in a initializer.
56
+
57
+ Sentry::Scope.prepend(Lamian::SentryScopePatch)
58
+ ```
59
+
60
+ ## Raven (deprecated)
61
+
62
+ ### Usage
63
+
64
+ Add this line to your Sentry initializer:
65
+
66
+ ```ruby
67
+ Raven::Context.prepend(Lamian::RavenContextExtension)
68
+ ```
69
+
70
+ ### Usage with Sidekiq
71
+
72
+ You should add Lamian middleware to the Sidekiq initializer like this:
73
+
74
+ ```ruby
75
+ config.server_middleware do |chain|
76
+ chain.prepend(Lamian::SidekiqRavenMiddleware)
77
+ end
78
+ ```
79
+
80
+ ## Contribution
81
+
82
+ Feel free to contribute by making PRs and Issues on [GitHub](https://github.com/JelF/lamian)
83
+ You also can contact me using my email begdory4+lamian@gmail.com
84
+
85
+ ## TODO
86
+
87
+ - It probably should be separated to `lamian` and `lamian-rails` gems.
88
+ Rails dependency is never cool
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+ require "yard"
7
+ require "pathname"
8
+ require "launchy"
9
+ require "uri"
10
+
11
+ ROOT = Pathname.new(__FILE__).join("..")
12
+
13
+ RSpec::Core::RakeTask.new(:spec)
14
+ RuboCop::RakeTask.new(:lint)
15
+
16
+ YARD::Rake::YardocTask.new(:doc) do |t|
17
+ t.files = Dir[ROOT.join("lib/**/*.rb")]
18
+ t.options = %w[--private]
19
+ end
20
+
21
+ def open_in_browser(path)
22
+ Launchy.open(URI.join("file:///", path.to_s))
23
+ end
24
+
25
+ namespace :doc do
26
+ desc "open doc"
27
+ task open: :doc do
28
+ open_in_browser ROOT.join("doc/frames.html")
29
+ end
30
+
31
+ desc "checks doc coverage"
32
+ task coverage: :doc do
33
+ # ideally you've already generated the database to .load it
34
+ # if not, have this task depend on the docs task.
35
+ YARD::Registry.load
36
+ objs = YARD::Registry.select do |o|
37
+ puts "pending #{o}" if /TODO|FIXME|@pending/.match?(o.docstring)
38
+ o.docstring.blank?
39
+ end
40
+
41
+ next if objs.empty?
42
+ puts "No documentation found for:"
43
+ objs.each { |x| puts "\t#{x}" }
44
+
45
+ raise "100% document coverage required"
46
+ end
47
+ end
48
+
49
+ task default: %i[lint doc:coverage spec]
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lamian"
5
+ require "semantic_logger"
6
+
7
+ require "pry"
8
+ Pry.start
data/bin/rake ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rake' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rake", "rake")
data/bin/rubocop ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rubocop' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("rubocop", "rubocop")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/lamian/config.rb CHANGED
@@ -6,9 +6,12 @@ module Lamian
6
6
  # General lamian configuration class
7
7
  # @attr formatter [Logger::Foramtter]
8
8
  # formatter to use in lamian, global
9
- Config = Struct.new(:formatter) do
9
+ # @attr raven_log_size_limit [Integer]
10
+ # size limit when sending lamian log to sentry, defaults to +500_000+
11
+ Config = Struct.new(:formatter, :raven_log_size_limit) do
10
12
  def initialize
11
13
  self.formatter = ::Logger::Formatter.new
14
+ self.raven_log_size_limit = 500_000
12
15
  end
13
16
  end
14
17
  end
data/lib/lamian/engine.rb CHANGED
@@ -14,5 +14,45 @@ module Lamian
14
14
  app.config.middleware.unshift(Lamian::Middleware)
15
15
  # :nocov:
16
16
  end
17
+
18
+ config.after_initialize do
19
+ # :nocov:
20
+ next unless defined?(Sentry)
21
+ next unless Sentry.initialized?
22
+
23
+ Sentry.configuration.before_send = rebuild_before_send
24
+ # :nocov:
25
+ end
26
+
27
+ # Reassembles the callback that runs before sending the event to the Sentry:
28
+ # connects the user callback with the callback that adds lamian logs to the event.
29
+ # @private
30
+ # @return [Proc] final callback.
31
+ def rebuild_before_send
32
+ defined_callback = Sentry.configuration.before_send || build_default_lambda
33
+ lamian_callback = build_lamian_callback
34
+
35
+ proc { |*args, **kwargs| lamian_callback.call(defined_callback.call(*args, **kwargs)) }
36
+ end
37
+
38
+ # Builds a callback, which does nothing.
39
+ # @private
40
+ # @return [Proc] empty callback.
41
+ def build_default_lambda
42
+ -> (event, _hint) { event }
43
+ end
44
+
45
+ # Builds a callback that adds logs to the event.
46
+ # @private
47
+ # @return [Proc] callback.
48
+ def build_lamian_callback
49
+ lambda do |event|
50
+ event.tap do |event|
51
+ extra = event&.extra or return
52
+ log = Lamian.dump_limited
53
+ extra[Lamian::SENTRY_EXTRA_KEY] = log if log
54
+ end
55
+ end
56
+ end
17
57
  end
18
58
  end
data/lib/lamian/logger.rb CHANGED
@@ -15,6 +15,7 @@ module Lamian
15
15
  end
16
16
 
17
17
  def initialize
18
+ super(nil)
18
19
  self.level = 0
19
20
  self.logdevs = []
20
21
  end
@@ -5,9 +5,7 @@ module Lamian::RavenContextExtension
5
5
  # Adds current lamian log to the extra part of all raven events generated inside Lamian.run block
6
6
  # @see https://www.rubydoc.info/gems/sentry-raven/0.9.2/Raven/Context#extra-instance_method
7
7
  def extra
8
- log = Lamian.dump(format: :txt)
9
- return super unless log
10
- extra = super || {}
11
- extra.merge(lamian_log: log)
8
+ log = Lamian.dump_limited
9
+ log ? super.merge!(Lamian::SENTRY_EXTRA_KEY => log) : super
12
10
  end
13
11
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lamian
4
+ # Custom appender for the `semantic_logger` library.
5
+ # This appender adds all logs to the current Lamian logger.
6
+ # Since Lamian stores logs in a thread variable,
7
+ # it is necessary that this appender writes logs synchronously:
8
+ # just call `SematicLogger.sync!` somewhere in the initialization process.
9
+ # @see https://logger.rocketjob.io Semantic Logger documentation.
10
+ class SemanticLoggerAppender < SemanticLogger::Subscriber
11
+ # Mapping between standard Logger severity and SemanticLogger log levels.
12
+ LOGGER_LEVELS_MAPPING = { trace: 0, debug: 0, info: 1, warn: 2, error: 3, fatal: 4 }.freeze
13
+
14
+ # The method to be implemented when creating a custom appender.
15
+ # @see https://logger.rocketjob.io/custom_appenders.html Documentation about custom appenders.
16
+ # @returns [Boolean]
17
+ def log(log)
18
+ mapped_level = LOGGER_LEVELS_MAPPING[log.level] || ::Logger::UNKNOWN
19
+ Lamian::Logger.current.add(mapped_level, log.message)
20
+
21
+ true
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lamian
4
+ # Patch for the `Sentry::Scope`. Extends the attribute accessor
5
+ # by adding an automatic lamian log dump.
6
+ # You should use this patch if you want to asynchronously send events.
7
+ # @example Prepending `Sentry::Scope` class
8
+ # Sentry::Scope.prepend(Lamian::SentryScopePatch) #=> Sentry::Scope
9
+ module SentryScopePatch
10
+ # Extra data defined in the scope.
11
+ # @return [String]
12
+ def extra
13
+ log = Lamian.dump(format: :txt)&.slice(0, Lamian.config.raven_log_size_limit)
14
+ log ? super.merge!(Lamian::SENTRY_EXTRA_KEY => log) : super
15
+ end
16
+ end
17
+ end
@@ -5,12 +5,10 @@ class Lamian::SidekiqRavenMiddleware
5
5
  # Adds current lamian log to the extra part of raven events generated inside sidekiq jobs
6
6
  def call(*)
7
7
  Lamian.run do
8
- begin
9
- yield
10
- rescue Exception # rubocop:disable Lint/RescueException
11
- Raven.extra_context(lamian_log: Lamian.dump(format: :txt))
12
- raise
13
- end
8
+ yield
9
+ rescue Exception # rubocop:disable Lint/RescueException
10
+ Raven.extra_context # Just trigger saving of the current log
11
+ raise
14
12
  end
15
13
  end
16
14
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A sidekiq middleware
4
+ class Lamian::SidekiqSentryMiddleware
5
+ # Adds current lamian log to the extra part of raven events generated inside sidekiq jobs
6
+ def call(*)
7
+ Lamian.run do
8
+ yield
9
+ rescue Exception # rubocop:disable Lint/RescueException
10
+ # Save current log
11
+ log = Lamian.dump_limited
12
+ Sentry.set_extras(Lamian::SENTRY_EXTRA_KEY => log) if log
13
+ raise
14
+ end
15
+ end
16
+ end
@@ -13,5 +13,5 @@ module Lamian
13
13
  # According to this, it is enought to specify '~> a.b'
14
14
  # if private API was not used and to specify '~> a.b.c' if it was
15
15
 
16
- VERSION = "1.1.0"
16
+ VERSION = "1.5.0"
17
17
  end
data/lib/lamian.rb CHANGED
@@ -12,6 +12,12 @@ module Lamian
12
12
  autoload :Middleware, "lamian/middleware"
13
13
  autoload :RavenContextExtension, "lamian/raven_context_extension"
14
14
  autoload :SidekiqRavenMiddleware, "lamian/sidekiq_raven_middleware"
15
+ autoload :SidekiqSentryMiddleware, "lamian/sidekiq_sentry_middleware"
16
+ autoload :SemanticLoggerAppender, "lamian/semantic_logger_appender"
17
+ autoload :SentryScopePatch, "lamian/sentry_scope_patch"
18
+
19
+ # The key under which logs are stored in the Sentry extra data.
20
+ SENTRY_EXTRA_KEY = :lamian_log
15
21
 
16
22
  require "lamian/engine"
17
23
 
@@ -45,12 +51,12 @@ module Lamian
45
51
  end
46
52
 
47
53
  # Collects logs sent inside block
48
- def run
49
- logger.run { yield }
54
+ def run(&block)
55
+ logger.run(&block)
50
56
  end
51
57
 
52
58
  # Dumps log collected in this run
53
- # @option format [Symbol]
59
+ # @param format [Symbol]
54
60
  # requested format of log. At this point, returns raw log if falsey
55
61
  # or log without controll sequences (such as '[23m') if truthy
56
62
  # value given (for now)
@@ -58,5 +64,11 @@ module Lamian
58
64
  def dump(format: nil)
59
65
  logger.dump(format: format)
60
66
  end
67
+
68
+ # Truncates the collected log to the specified limit and dumps it.
69
+ # @return [String, nil] truncated formatted log.
70
+ def dump_limited
71
+ dump(format: :txt)&.slice(0, Lamian.config.raven_log_size_limit)
72
+ end
61
73
  end
62
74
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lamian
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JelF
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-26 00:00:00.000000000 Z
11
+ date: 2021-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -25,145 +25,187 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: bundler-audit
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ci-helper
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: launchy
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
32
67
  - !ruby/object:Gem::Version
33
- version: '1.12'
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
34
76
  type: :development
35
77
  prerelease: false
36
78
  version_requirements: !ruby/object:Gem::Requirement
37
79
  requirements:
38
- - - "~>"
80
+ - - ">="
39
81
  - !ruby/object:Gem::Version
40
- version: '1.12'
82
+ version: '0'
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: rake
43
85
  requirement: !ruby/object:Gem::Requirement
44
86
  requirements:
45
- - - "~>"
87
+ - - ">="
46
88
  - !ruby/object:Gem::Version
47
- version: '10.0'
89
+ version: '0'
48
90
  type: :development
49
91
  prerelease: false
50
92
  version_requirements: !ruby/object:Gem::Requirement
51
93
  requirements:
52
- - - "~>"
94
+ - - ">="
53
95
  - !ruby/object:Gem::Version
54
- version: '10.0'
96
+ version: '0'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: rspec
57
99
  requirement: !ruby/object:Gem::Requirement
58
100
  requirements:
59
- - - "~>"
101
+ - - ">="
60
102
  - !ruby/object:Gem::Version
61
- version: '3.0'
103
+ version: '0'
62
104
  type: :development
63
105
  prerelease: false
64
106
  version_requirements: !ruby/object:Gem::Requirement
65
107
  requirements:
66
- - - "~>"
108
+ - - ">="
67
109
  - !ruby/object:Gem::Version
68
- version: '3.0'
110
+ version: '0'
69
111
  - !ruby/object:Gem::Dependency
70
112
  name: rubocop-config-umbrellio
71
113
  requirement: !ruby/object:Gem::Requirement
72
114
  requirements:
73
- - - '='
115
+ - - ">="
74
116
  - !ruby/object:Gem::Version
75
- version: 0.49.1.4
117
+ version: '0'
76
118
  type: :development
77
119
  prerelease: false
78
120
  version_requirements: !ruby/object:Gem::Requirement
79
121
  requirements:
80
- - - '='
122
+ - - ">="
81
123
  - !ruby/object:Gem::Version
82
- version: 0.49.1.4
124
+ version: '0'
83
125
  - !ruby/object:Gem::Dependency
84
- name: pry
126
+ name: semantic_logger
85
127
  requirement: !ruby/object:Gem::Requirement
86
128
  requirements:
87
- - - "~>"
129
+ - - ">="
88
130
  - !ruby/object:Gem::Version
89
- version: '0.10'
131
+ version: '0'
90
132
  type: :development
91
133
  prerelease: false
92
134
  version_requirements: !ruby/object:Gem::Requirement
93
135
  requirements:
94
- - - "~>"
136
+ - - ">="
95
137
  - !ruby/object:Gem::Version
96
- version: '0.10'
138
+ version: '0'
97
139
  - !ruby/object:Gem::Dependency
98
- name: coveralls
140
+ name: sentry-raven
99
141
  requirement: !ruby/object:Gem::Requirement
100
142
  requirements:
101
- - - "~>"
143
+ - - ">="
102
144
  - !ruby/object:Gem::Version
103
- version: '0.8'
145
+ version: '0'
104
146
  type: :development
105
147
  prerelease: false
106
148
  version_requirements: !ruby/object:Gem::Requirement
107
149
  requirements:
108
- - - "~>"
150
+ - - ">="
109
151
  - !ruby/object:Gem::Version
110
- version: '0.8'
152
+ version: '0'
111
153
  - !ruby/object:Gem::Dependency
112
- name: yard
154
+ name: sentry-ruby
113
155
  requirement: !ruby/object:Gem::Requirement
114
156
  requirements:
115
- - - "~>"
157
+ - - ">="
116
158
  - !ruby/object:Gem::Version
117
- version: '0.9'
159
+ version: '0'
118
160
  type: :development
119
161
  prerelease: false
120
162
  version_requirements: !ruby/object:Gem::Requirement
121
163
  requirements:
122
- - - "~>"
164
+ - - ">="
123
165
  - !ruby/object:Gem::Version
124
- version: '0.9'
166
+ version: '0'
125
167
  - !ruby/object:Gem::Dependency
126
- name: launchy
168
+ name: simplecov
127
169
  requirement: !ruby/object:Gem::Requirement
128
170
  requirements:
129
- - - "~>"
171
+ - - ">="
130
172
  - !ruby/object:Gem::Version
131
- version: 2.4.3
173
+ version: '0'
132
174
  type: :development
133
175
  prerelease: false
134
176
  version_requirements: !ruby/object:Gem::Requirement
135
177
  requirements:
136
- - - "~>"
178
+ - - ">="
137
179
  - !ruby/object:Gem::Version
138
- version: 2.4.3
180
+ version: '0'
139
181
  - !ruby/object:Gem::Dependency
140
- name: json
182
+ name: simplecov-lcov
141
183
  requirement: !ruby/object:Gem::Requirement
142
184
  requirements:
143
185
  - - ">="
144
186
  - !ruby/object:Gem::Version
145
- version: 2.1.0
187
+ version: '0'
146
188
  type: :development
147
189
  prerelease: false
148
190
  version_requirements: !ruby/object:Gem::Requirement
149
191
  requirements:
150
192
  - - ">="
151
193
  - !ruby/object:Gem::Version
152
- version: 2.1.0
194
+ version: '0'
153
195
  - !ruby/object:Gem::Dependency
154
- name: sentry-raven
196
+ name: yard
155
197
  requirement: !ruby/object:Gem::Requirement
156
198
  requirements:
157
- - - "~>"
199
+ - - ">="
158
200
  - !ruby/object:Gem::Version
159
- version: 2.7.4
201
+ version: '0'
160
202
  type: :development
161
203
  prerelease: false
162
204
  version_requirements: !ruby/object:Gem::Requirement
163
205
  requirements:
164
- - - "~>"
206
+ - - ">="
165
207
  - !ruby/object:Gem::Version
166
- version: 2.7.4
208
+ version: '0'
167
209
  description: Add logs to your error messages, using exception_notifier or smth like
168
210
  it
169
211
  email:
@@ -172,6 +214,19 @@ executables: []
172
214
  extensions: []
173
215
  extra_rdoc_files: []
174
216
  files:
217
+ - ".github/workflows/test.yml"
218
+ - ".gitignore"
219
+ - ".rubocop.yml"
220
+ - Changelog.md
221
+ - Gemfile
222
+ - Gemfile.lock
223
+ - LICENSE.txt
224
+ - README.md
225
+ - Rakefile
226
+ - bin/console
227
+ - bin/rake
228
+ - bin/rubocop
229
+ - bin/setup
175
230
  - lib/lamian.rb
176
231
  - lib/lamian/config.rb
177
232
  - lib/lamian/engine.rb
@@ -181,12 +236,16 @@ files:
181
236
  - lib/lamian/rails_views/exception_notifier/_request_log.html.erb
182
237
  - lib/lamian/rails_views/exception_notifier/_request_log.text.erb
183
238
  - lib/lamian/raven_context_extension.rb
239
+ - lib/lamian/semantic_logger_appender.rb
240
+ - lib/lamian/sentry_scope_patch.rb
184
241
  - lib/lamian/sidekiq_raven_middleware.rb
242
+ - lib/lamian/sidekiq_sentry_middleware.rb
185
243
  - lib/lamian/version.rb
186
244
  homepage: https://github.com/umbrellio/lamian
187
- licenses: []
245
+ licenses:
246
+ - MIT
188
247
  metadata: {}
189
- post_install_message:
248
+ post_install_message:
190
249
  rdoc_options: []
191
250
  require_paths:
192
251
  - lib
@@ -194,16 +253,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
194
253
  requirements:
195
254
  - - ">="
196
255
  - !ruby/object:Gem::Version
197
- version: '0'
256
+ version: 2.5.0
198
257
  required_rubygems_version: !ruby/object:Gem::Requirement
199
258
  requirements:
200
259
  - - ">="
201
260
  - !ruby/object:Gem::Version
202
261
  version: '0'
203
262
  requirements: []
204
- rubyforge_project:
205
- rubygems_version: 2.5.2.3
206
- signing_key:
263
+ rubygems_version: 3.3.0.dev
264
+ signing_key:
207
265
  specification_version: 4
208
266
  summary: Add logs to your error messages
209
267
  test_files: []