lamian 1.2.0 → 1.4.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: 595ed31da060bf4d84295ed89509fe3668f3666a
4
- data.tar.gz: 869e4c8b88eead8d73542faba6763e3eff036c24
2
+ SHA256:
3
+ metadata.gz: d42eee8929a0bb372234198aade127f4ea73bbf7315133d2f88e6e6caff69084
4
+ data.tar.gz: f173c941c4ab3d54d54a85a6c53742bfd0dab1b7b6333920dbb0ffebdebe772e
5
5
  SHA512:
6
- metadata.gz: 7836270051619e4cb130a730625af6d265fcf172192a0702ce048782ea31730e526e8cae2bee2d4431424c1b0edd7603ff5920bb08088f380742bdd31ccf750e
7
- data.tar.gz: 69bd8f97dd76416699b6ffdc3b6f441e9c5fa7d5313e51d4bf4cea7f85529380b229ccbb2085c01957139461972ef9e345784016a4e33054ffff8acd40201037
6
+ metadata.gz: 4d6f8d04d0f95eae97dd23450507d01e49afc7bfa82ec0a4d5a35db0ab06a38595e79f41a8f60f45f500bfc9dc5f0d3bc6dff77f446ad6c8d26bc42338a044b9
7
+ data.tar.gz: '05872e41faae73675db913eff599a98ec497e2eaaa01335b5dcf8d54b3238e1a858d449667cfe415ec1ed17bafc38a88b9b1b4091e05e4c683ce2ab88b31e863'
@@ -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.5, 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.4.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.10)
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.2.2)
239
+ actionpack (>= 4.0)
240
+ activesupport (>= 4.0)
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,78 @@
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
+ ## Raven (deprecated)
51
+
52
+ ### Usage
53
+
54
+ Add this line to your Sentry initializer:
55
+
56
+ ```ruby
57
+ Raven::Context.prepend(Lamian::RavenContextExtension)
58
+ ```
59
+
60
+ ### Usage with Sidekiq
61
+
62
+ You should add Lamian middleware to the Sidekiq initializer like this:
63
+
64
+ ```ruby
65
+ config.server_middleware do |chain|
66
+ chain.prepend(Lamian::SidekiqRavenMiddleware)
67
+ end
68
+ ```
69
+
70
+ ## Contribution
71
+
72
+ Feel free to contribute by making PRs and Issues on [GitHub](https://github.com/JelF/lamian)
73
+ You also can contact me using my email begdory4+lamian@gmail.com
74
+
75
+ ## TODO
76
+
77
+ - It probably should be separated to `lamian` and `lamian-rails` gems.
78
+ 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/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,7 +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)&.slice(0, Lamian.config.raven_log_size_limit)
9
- log ? super.merge!(lamian_log: log) : super
8
+ log = Lamian.dump_limited
9
+ log ? super.merge!(Lamian::SENTRY_EXTRA_KEY => log) : super
10
10
  end
11
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
@@ -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 # Just trigger saving of the current log
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.2.0"
16
+ VERSION = "1.4.0"
17
17
  end
data/lib/lamian.rb CHANGED
@@ -12,6 +12,11 @@ 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
+
18
+ # The key under which logs are stored in the Sentry extra data.
19
+ SENTRY_EXTRA_KEY = :lamian_log
15
20
 
16
21
  require "lamian/engine"
17
22
 
@@ -45,12 +50,12 @@ module Lamian
45
50
  end
46
51
 
47
52
  # Collects logs sent inside block
48
- def run
49
- logger.run { yield }
53
+ def run(&block)
54
+ logger.run(&block)
50
55
  end
51
56
 
52
57
  # Dumps log collected in this run
53
- # @option format [Symbol]
58
+ # @param format [Symbol]
54
59
  # requested format of log. At this point, returns raw log if falsey
55
60
  # or log without controll sequences (such as '[23m') if truthy
56
61
  # value given (for now)
@@ -58,5 +63,11 @@ module Lamian
58
63
  def dump(format: nil)
59
64
  logger.dump(format: format)
60
65
  end
66
+
67
+ # Truncates the collected log to the specified limit and dumps it.
68
+ # @return [String, nil] truncated formatted log.
69
+ def dump_limited
70
+ dump(format: :txt)&.slice(0, Lamian.config.raven_log_size_limit)
71
+ end
61
72
  end
62
73
  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.2.0
4
+ version: 1.4.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-30 00:00:00.000000000 Z
11
+ date: 2021-11-01 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,15 @@ 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
184
240
  - lib/lamian/sidekiq_raven_middleware.rb
241
+ - lib/lamian/sidekiq_sentry_middleware.rb
185
242
  - lib/lamian/version.rb
186
243
  homepage: https://github.com/umbrellio/lamian
187
- licenses: []
244
+ licenses:
245
+ - MIT
188
246
  metadata: {}
189
- post_install_message:
247
+ post_install_message:
190
248
  rdoc_options: []
191
249
  require_paths:
192
250
  - lib
@@ -194,16 +252,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
194
252
  requirements:
195
253
  - - ">="
196
254
  - !ruby/object:Gem::Version
197
- version: '0'
255
+ version: 2.5.0
198
256
  required_rubygems_version: !ruby/object:Gem::Requirement
199
257
  requirements:
200
258
  - - ">="
201
259
  - !ruby/object:Gem::Version
202
260
  version: '0'
203
261
  requirements: []
204
- rubyforge_project:
205
- rubygems_version: 2.5.2.3
206
- signing_key:
262
+ rubygems_version: 3.2.30
263
+ signing_key:
207
264
  specification_version: 4
208
265
  summary: Add logs to your error messages
209
266
  test_files: []