loga 2.1.0 → 2.1.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -2
- data/README.md +46 -14
- data/circle.yml +6 -3
- data/lib/loga/ext/core/tempfile.rb +7 -0
- data/lib/loga/railtie.rb +12 -5
- data/lib/loga/version.rb +1 -1
- data/spec/fixtures/random_bin +0 -0
- data/spec/integration/rails/railtie_spec.rb +7 -0
- data/spec/support/request_spec.rb +19 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ea55004c4f02786aa7326eddf736f2a3f47bdac
|
4
|
+
data.tar.gz: 79b1ef4aca4cd6ac9aadd3a501cfdc84dca7ca91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9047a4c1a74ddba23a41216915412f5c24bae7e862a2a03b417432cd6619102d939b90217f30dcbf89afcfde06c553698b702f89465173d1bafced72a09f8ae
|
7
|
+
data.tar.gz: b9b82664a07fc4a4175301734a332bbf8110660d493fd0d5226f9042a908b65181aca610fe05628fc546fa59a92afa52b92ebdb1bec03b08aedcd919caea93a3
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,12 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
6
|
|
7
|
-
## [2.1.
|
7
|
+
## [2.1.1] - 2016-12-02
|
8
|
+
### Fixed
|
9
|
+
- Encoding error when converting uploaded file to JSON
|
10
|
+
[rails/rails#25250](https://github.com/rails/rails/issues/25250)
|
11
|
+
|
12
|
+
## [2.1.0] - 2016-11-17
|
8
13
|
## [2.1.0.pre.1]
|
9
14
|
### Changed
|
10
15
|
- Replace `ActiveSupport::Logger::SimpleFormatter` with `Loga::Formatters::SimpleFormatter`
|
@@ -48,7 +53,8 @@ when using simple format. The formatter adds level, timestamp, pid and tags prep
|
|
48
53
|
### Changed
|
49
54
|
- Silence ActionDispatch::DebugExceptions' logger
|
50
55
|
|
51
|
-
[2.1.
|
56
|
+
[2.1.1]: https://github.com/FundingCircle/loga/compare/v2.1.0...v2.1.1
|
57
|
+
[2.1.0]: https://github.com/FundingCircle/loga/compare/v2.0.0...v2.1.0
|
52
58
|
[2.1.0.pre.1]: https://github.com/FundingCircle/loga/compare/v2.0.0...v2.1.0.pre.1
|
53
59
|
[2.0.0]: https://github.com/FundingCircle/loga/compare/v1.4.0...v2.0.0
|
54
60
|
[2.0.0.pre.3]: https://github.com/FundingCircle/loga/compare/v2.0.0.pre.2...v2.0.0.pre.3
|
data/README.md
CHANGED
@@ -1,11 +1,17 @@
|
|
1
|
-
# Loga
|
1
|
+
# Loga
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/loga)
|
4
|
+
[](https://circleci.com/gh/FundingCircle/loga/tree/master)
|
5
|
+
[](https://codeclimate.com/repos/5563694f6956805723005d2f/feed)
|
6
|
+
[](https://codeclimate.com/repos/5563694f6956805723005d2f/coverage)
|
7
|
+
[](https://gemnasium.com/github.com/FundingCircle/loga)
|
2
8
|
|
3
9
|
## Description
|
4
10
|
|
5
11
|
Loga provides consistent logging across frameworks and environments.
|
6
12
|
|
7
13
|
Includes:
|
8
|
-
- One logger for all environments
|
14
|
+
- One tagged logger for all environments
|
9
15
|
- Human readable logs for development
|
10
16
|
- Structured logs for production ([GELF](http://docs.graylog.org/en/2.1/pages/gelf.html))
|
11
17
|
- One Rack logger for all Rack based applications
|
@@ -31,7 +37,7 @@ Includes:
|
|
31
37
|
Add this line to your application's Gemfile:
|
32
38
|
|
33
39
|
```
|
34
|
-
gem 'loga'
|
40
|
+
gem 'loga'
|
35
41
|
```
|
36
42
|
|
37
43
|
### Rails
|
@@ -41,7 +47,7 @@ Let Loga know what your application name is and Loga will do the rest.
|
|
41
47
|
```ruby
|
42
48
|
# config/application.rb
|
43
49
|
class MyApp::Application < Rails::Application
|
44
|
-
config.loga = { service_name: '
|
50
|
+
config.loga = { service_name: 'my_app' }
|
45
51
|
end
|
46
52
|
```
|
47
53
|
|
@@ -62,7 +68,7 @@ class MyApp::Application < Rails::Application
|
|
62
68
|
config.loga = {
|
63
69
|
device: File.open("log/application.log", 'a'),
|
64
70
|
format: :gelf,
|
65
|
-
service_name: '
|
71
|
+
service_name: 'my_app',
|
66
72
|
}
|
67
73
|
end
|
68
74
|
```
|
@@ -167,21 +173,41 @@ Sinatra request output is identical to Rails but without the `_request.controlle
|
|
167
173
|
Logger output:
|
168
174
|
|
169
175
|
```ruby
|
170
|
-
Rails.logger
|
176
|
+
# Rails.logger
|
171
177
|
# or
|
178
|
+
# Loga.logger
|
179
|
+
|
180
|
+
Loga.configure(service_name: 'my_app', format: :gelf)
|
181
|
+
|
172
182
|
Loga.logger.info('I love Loga')
|
183
|
+
Loga.logger.tagged(%w(USER_123 CRM)) do
|
184
|
+
Loga.logger.info('I love Loga with tags')
|
185
|
+
end
|
186
|
+
```
|
187
|
+
|
188
|
+
```json
|
189
|
+
{
|
190
|
+
"_service.name": "my_app",
|
191
|
+
"_service.version": "v1.0.0",
|
192
|
+
"_tags": "",
|
193
|
+
"host": "example.com",
|
194
|
+
"level": 6,
|
195
|
+
"short_message": "I love Loga",
|
196
|
+
"timestamp": 1479402679.663,
|
197
|
+
"version": "1.1"
|
198
|
+
}
|
173
199
|
```
|
174
200
|
|
175
201
|
```json
|
176
202
|
{
|
177
|
-
"_service.name":
|
178
|
-
"_service.version":
|
179
|
-
"_tags":
|
203
|
+
"_service.name": "my_app",
|
204
|
+
"_service.version": "v1.0.0",
|
205
|
+
"_tags": "USER_123 CRM",
|
180
206
|
"host": "example.com",
|
181
|
-
"level":
|
182
|
-
"short_message":
|
183
|
-
"timestamp":
|
184
|
-
"version":
|
207
|
+
"level": 6,
|
208
|
+
"short_message": "I love Loga",
|
209
|
+
"timestamp": 1479402706.102,
|
210
|
+
"version": "1.1"
|
185
211
|
}
|
186
212
|
```
|
187
213
|
|
@@ -210,11 +236,17 @@ I, [2016-11-15T16:10:08.645521+00:00 #1][12345] GET /ok 200 in 0ms type=request
|
|
210
236
|
Logger output:
|
211
237
|
|
212
238
|
```ruby
|
239
|
+
Loga.configure(service_name: 'my_app', format: :simple)
|
240
|
+
|
213
241
|
Loga.logger.info('I love Loga')
|
242
|
+
Loga.logger.tagged(%w(USER_123 CRM)) do
|
243
|
+
Loga.logger.info('I love Loga with tags')
|
244
|
+
end
|
214
245
|
```
|
215
246
|
|
216
247
|
```
|
217
|
-
I, [
|
248
|
+
I, [2016-11-17T17:07:46.714215+00:00 #595] I love Loga
|
249
|
+
I, [2016-11-17T17:07:46.725624+00:00 #595][USER_123 CRM] I love Loga with tags
|
218
250
|
```
|
219
251
|
|
220
252
|
## Road map
|
data/circle.yml
CHANGED
@@ -14,7 +14,10 @@ test:
|
|
14
14
|
- rvm-exec 2.3.1 bundle exec codeclimate-test-reporter
|
15
15
|
deployment:
|
16
16
|
gemfury:
|
17
|
-
tag:
|
17
|
+
tag: /^v\d.+/
|
18
|
+
owner: FundingCircle
|
18
19
|
commands:
|
19
|
-
- "gem build
|
20
|
-
-
|
20
|
+
- "gem build $CIRCLE_PROJECT_REPONAME.gemspec"
|
21
|
+
- 'echo :rubygems_api_key: ${RUBYGEMS_API_KEY} > ~/.gem/credentials'
|
22
|
+
- "chmod 0600 ~/.gem/credentials"
|
23
|
+
- "gem push $CIRCLE_PROJECT_REPONAME-$(echo $CIRCLE_TAG | sed -e 's/v//').gem"
|
data/lib/loga/railtie.rb
CHANGED
@@ -17,6 +17,7 @@ module Loga
|
|
17
17
|
|
18
18
|
def call
|
19
19
|
validate_user_options
|
20
|
+
change_tempfile_as_json
|
20
21
|
Loga.configure(user_options, rails_options)
|
21
22
|
app.config.colorize_logging = false if Loga.configuration.structured?
|
22
23
|
app.config.logger = Loga.logger
|
@@ -51,17 +52,23 @@ module Loga
|
|
51
52
|
Rails::VERSION::MAJOR > 3 ? app.config.autoflush_log : true
|
52
53
|
end
|
53
54
|
|
54
|
-
# rubocop:disable Metrics/LineLength
|
55
55
|
def validate_user_options
|
56
56
|
if user_options[:tags].present?
|
57
|
-
raise Loga::ConfigurationError,
|
57
|
+
raise Loga::ConfigurationError,
|
58
|
+
'Configure tags with Rails config.log_tags'
|
58
59
|
elsif user_options[:level].present?
|
59
|
-
raise Loga::ConfigurationError,
|
60
|
+
raise Loga::ConfigurationError,
|
61
|
+
'Configure level with Rails config.log_level'
|
60
62
|
elsif user_options[:filter_parameters].present?
|
61
|
-
raise Loga::ConfigurationError,
|
63
|
+
raise Loga::ConfigurationError,
|
64
|
+
'Configure filter_parameters with Rails config.filter_parameters'
|
62
65
|
end
|
63
66
|
end
|
64
|
-
|
67
|
+
|
68
|
+
# Fixes encoding error when converting uploaded file to JSON
|
69
|
+
def change_tempfile_as_json
|
70
|
+
require 'loga/ext/core/tempfile'
|
71
|
+
end
|
65
72
|
end
|
66
73
|
|
67
74
|
initializer :loga_initialize_logger, before: :initialize_logger do |app|
|
data/lib/loga/version.rb
CHANGED
Binary file
|
@@ -4,6 +4,13 @@ RSpec.describe Loga::Railtie do
|
|
4
4
|
let(:app) { Rails.application }
|
5
5
|
let(:middlewares) { app.middleware.middlewares }
|
6
6
|
|
7
|
+
describe 'Tempfile' do
|
8
|
+
let(:tempfile) { Tempfile.new('README.md') }
|
9
|
+
it 'monkey patches #as_json' do
|
10
|
+
expect(tempfile.as_json).to eql(tempfile.to_s)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
7
14
|
context 'development', if: Rails.env.development? do
|
8
15
|
describe 'loga_initialize_logger' do
|
9
16
|
let(:formatter) { Loga::Formatters::SimpleFormatter }
|
@@ -181,4 +181,23 @@ RSpec.shared_examples 'request logger' do
|
|
181
181
|
end
|
182
182
|
end
|
183
183
|
end
|
184
|
+
|
185
|
+
describe 'when the request uploads a binary file', focus: true do
|
186
|
+
it 'logs the request' do
|
187
|
+
post '/users?username=yoshi',
|
188
|
+
bob_file: Rack::Test::UploadedFile.new('spec/fixtures/random_bin')
|
189
|
+
|
190
|
+
expect(last_log_entry).to include(
|
191
|
+
'short_message' => 'POST /users?username=yoshi 200 in 0ms',
|
192
|
+
'level' => 6,
|
193
|
+
'_request.params' => {
|
194
|
+
'username' => 'yoshi',
|
195
|
+
'bob_file' => include(
|
196
|
+
'filename' => 'random_bin',
|
197
|
+
'name' => 'bob_file',
|
198
|
+
),
|
199
|
+
},
|
200
|
+
)
|
201
|
+
end
|
202
|
+
end
|
184
203
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loga
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Funding Circle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -219,6 +219,7 @@ files:
|
|
219
219
|
- lib/loga.rb
|
220
220
|
- lib/loga/configuration.rb
|
221
221
|
- lib/loga/event.rb
|
222
|
+
- lib/loga/ext/core/tempfile.rb
|
222
223
|
- lib/loga/ext/rails/rack/debug_exceptions.rb
|
223
224
|
- lib/loga/ext/rails/rack/logger.rb
|
224
225
|
- lib/loga/ext/rails/rack/logger3.rb
|
@@ -329,6 +330,7 @@ files:
|
|
329
330
|
- spec/fixtures/rails50/public/apple-touch-icon.png
|
330
331
|
- spec/fixtures/rails50/public/favicon.ico
|
331
332
|
- spec/fixtures/rails50/public/robots.txt
|
333
|
+
- spec/fixtures/random_bin
|
332
334
|
- spec/integration/rails/railtie_spec.rb
|
333
335
|
- spec/integration/rails/request_spec.rb
|
334
336
|
- spec/integration/sinatra_spec.rb
|
@@ -366,7 +368,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
366
368
|
version: '0'
|
367
369
|
requirements: []
|
368
370
|
rubyforge_project:
|
369
|
-
rubygems_version: 2.5.1
|
371
|
+
rubygems_version: 2.4.5.1
|
370
372
|
signing_key:
|
371
373
|
specification_version: 4
|
372
374
|
summary: Facilitate log aggregation via unified logging
|
@@ -466,6 +468,7 @@ test_files:
|
|
466
468
|
- spec/fixtures/rails50/public/apple-touch-icon.png
|
467
469
|
- spec/fixtures/rails50/public/favicon.ico
|
468
470
|
- spec/fixtures/rails50/public/robots.txt
|
471
|
+
- spec/fixtures/random_bin
|
469
472
|
- spec/integration/rails/railtie_spec.rb
|
470
473
|
- spec/integration/rails/request_spec.rb
|
471
474
|
- spec/integration/sinatra_spec.rb
|
@@ -483,4 +486,3 @@ test_files:
|
|
483
486
|
- spec/unit/loga/service_version_strategies_spec.rb
|
484
487
|
- spec/unit/loga/utilities_spec.rb
|
485
488
|
- spec/unit/loga_spec.rb
|
486
|
-
has_rdoc:
|