better_logs 0.1.0 → 0.2.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
2
  SHA1:
3
- metadata.gz: ece6d96bc5daf1b196109b2c1c2862ea7a148a77
4
- data.tar.gz: c109e15ba3a254740b285505310bdfbde6bb6037
3
+ metadata.gz: 521fb57af9ac3d78d727ec9edf639525aa35af90
4
+ data.tar.gz: 9433ca34f7841ea1de887fb09cf84e3617e7547e
5
5
  SHA512:
6
- metadata.gz: 485eadc726d53f1b691872d19ccab0cb33ddb17f4352eb2883ca64f0b82eeb6da0d83c67f4e91407a719efa4982c9f1f384985c045104f116a264b01e67608e1
7
- data.tar.gz: 59655ca7c6337bc82ca761c0fe69dbcbcbb62ead6b416c24e064c1571502724b23731e6356ff001a25920d6ee53d12d5b004ca1561f7ae57ded6638e70b5f894
6
+ metadata.gz: 5ece79f690f24d8dbe0319974ac53fc887db26c21c2a7fba9ac467f99a43cabe99a430db7240b645fca072f283a347ef385f0fef7a991664eb3e89aa52e013a2
7
+ data.tar.gz: afbd7540449d2ab74f22cb2fd5aaabf0ea70e882cb715170fc09ce98b922e4c0d75344cfb26dfc0aa3a2c0565728466ecf744240cef52b97523f15c94d909112
data/Gemfile CHANGED
@@ -1,16 +1,17 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activesupport', '~> 4.0'
4
- gem 'actionpack', '~> 4.0'
5
- gem 'railties', '~> 4.0'
6
- gem 'flat_keys', '~> 0.0'
3
+ gem 'activesupport', '~> 4.0'
4
+ gem 'actionpack', '~> 4.0'
5
+ gem 'railties', '~> 4.0'
6
+ gem 'flat_keys', '~> 0.0'
7
+ gem 'useragent', '~> 0.10'
7
8
 
8
9
  group :development do
9
- gem 'rdoc', '~> 4.1'
10
- gem 'bundler', '~> 1.0'
11
- gem 'jeweler', '~> 2.0'
12
- gem 'rspec', '~> 2.14'
13
- gem 'guard-rspec', '~> 4.2'
14
- gem 'terminal-notifier-guard', '~> 1.5'
15
- gem 'codeclimate-test-reporter', '~> 0.3', require: nil
10
+ gem 'rdoc', '~> 4.1'
11
+ gem 'bundler', '~> 1.0'
12
+ gem 'jeweler', '~> 2.0'
13
+ gem 'rspec', '~> 2.14'
14
+ gem 'guard-rspec', '~> 4.2'
15
+ gem 'terminal-notifier-guard', '~> 1.5'
16
+ gem 'codeclimate-test-reporter', '~> 0.3', require: nil
16
17
  end
data/Gemfile.lock CHANGED
@@ -128,6 +128,7 @@ GEM
128
128
  timers (1.1.0)
129
129
  tzinfo (1.1.0)
130
130
  thread_safe (~> 0.1)
131
+ useragent (0.10.0)
131
132
 
132
133
  PLATFORMS
133
134
  ruby
@@ -144,3 +145,4 @@ DEPENDENCIES
144
145
  rdoc (~> 4.1)
145
146
  rspec (~> 2.14)
146
147
  terminal-notifier-guard (~> 1.5)
148
+ useragent (~> 0.10)
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # BetterLogs [![Build Status](https://travis-ci.org/techthumb/better_logs.svg?branch=v0.1.0)](https://travis-ci.org/techthumb/better_logs) [![Gem Version](https://badge.fury.io/rb/better_logs.svg)](http://badge.fury.io/rb/better_logs) [![Code Climate](https://codeclimate.com/repos/535a5dcae30ba03fdc00efe2/badges/1196b8f5d38c79f87546/gpa.png)](https://codeclimate.com/repos/535a5dcae30ba03fdc00efe2/feed) [![Code Climate](https://codeclimate.com/repos/535a5dcae30ba03fdc00efe2/badges/1196b8f5d38c79f87546/coverage.png)](https://codeclimate.com/repos/535a5dcae30ba03fdc00efe2/feed)
2
+
3
+ Better Logs adds an additional two log lines for all HTTP requests.
4
+ Currently, it logs data in key=value pairs to allow for Splunk indexing.
5
+
6
+ ```
7
+ format=html method=GET path=/ status=200 view_runtime=45.67 db_runtime=23.45 controller=rails/welcome action=index
8
+ ```
9
+ ```
10
+ remote_ip=127.0.0.1 browser_name=Chrome browser_platform=Macintosh browser_version=34.0.1847.131
11
+ ```
12
+
13
+ ## Installation
14
+ Add this to your Gemfile
15
+ ```ruby
16
+ gem 'better_logs'
17
+ ```
18
+
19
+ ## Get in touch!
20
+ If you're using ```better_logs```, I'd love to hear from you. Drop me a line and tell me what you think at: ```kunal+better_logs@techthumb.in```
21
+
22
+ ## Contributing
23
+ 1. Fork it
24
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
25
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
26
+ 4. Push to the branch (`git push origin my-new-feature`)
27
+ 5. Create new Pull Request
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/better_logs.gemspec CHANGED
@@ -2,21 +2,21 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: better_logs 0.1.0 ruby lib
5
+ # stub: better_logs 0.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "better_logs"
9
- s.version = "0.1.0"
9
+ s.version = "0.2.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Kunal Parikh"]
14
- s.date = "2014-04-27"
14
+ s.date = "2014-05-02"
15
15
  s.description = "Logging for Rails request/response lifecycle in a machine readable format (starting with Splunk)"
16
16
  s.email = "kunal@techthumb.in"
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE.txt",
19
- "README.rdoc"
19
+ "README.md"
20
20
  ]
21
21
  s.files = [
22
22
  ".coveralls.yml",
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  "Gemfile.lock",
27
27
  "Guardfile",
28
28
  "LICENSE.txt",
29
- "README.rdoc",
29
+ "README.md",
30
30
  "Rakefile",
31
31
  "VERSION",
32
32
  "better_logs.gemspec",
@@ -34,18 +34,23 @@ Gem::Specification.new do |s|
34
34
  "lib/better_logs/action_controller.rb",
35
35
  "lib/better_logs/action_controller/log_subscriber.rb",
36
36
  "lib/better_logs/action_controller/payload.rb",
37
+ "lib/better_logs/action_dispatch.rb",
38
+ "lib/better_logs/action_dispatch/log_subscriber.rb",
39
+ "lib/better_logs/action_dispatch/payload.rb",
37
40
  "lib/better_logs/formatters.rb",
38
41
  "lib/better_logs/formatters/key_value_formatter.rb",
39
42
  "lib/better_logs/initializer.rb",
40
43
  "lib/better_logs/railtie.rb",
41
44
  "spec/lib/better_logs/action_controller/log_subscriber_spec.rb",
42
45
  "spec/lib/better_logs/action_controller/payload_spec.rb",
46
+ "spec/lib/better_logs/action_dispatch/log_subscriber_spec.rb",
47
+ "spec/lib/better_logs/action_dispatch/payload_spec.rb",
43
48
  "spec/lib/better_logs/formatters/key_value_formatter_spec.rb",
44
49
  "spec/spec_helper.rb"
45
50
  ]
46
51
  s.homepage = "http://github.com/techthumb/better_logs"
47
52
  s.licenses = ["MIT"]
48
- s.rubygems_version = "2.2.1"
53
+ s.rubygems_version = "2.2.2"
49
54
  s.summary = "Better logging for Rails request/response lifecycle."
50
55
 
51
56
  if s.respond_to? :specification_version then
@@ -56,6 +61,7 @@ Gem::Specification.new do |s|
56
61
  s.add_runtime_dependency(%q<actionpack>, ["~> 4.0"])
57
62
  s.add_runtime_dependency(%q<railties>, ["~> 4.0"])
58
63
  s.add_runtime_dependency(%q<flat_keys>, ["~> 0.0"])
64
+ s.add_runtime_dependency(%q<useragent>, ["~> 0.10"])
59
65
  s.add_development_dependency(%q<rdoc>, ["~> 4.1"])
60
66
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
61
67
  s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
@@ -68,6 +74,7 @@ Gem::Specification.new do |s|
68
74
  s.add_dependency(%q<actionpack>, ["~> 4.0"])
69
75
  s.add_dependency(%q<railties>, ["~> 4.0"])
70
76
  s.add_dependency(%q<flat_keys>, ["~> 0.0"])
77
+ s.add_dependency(%q<useragent>, ["~> 0.10"])
71
78
  s.add_dependency(%q<rdoc>, ["~> 4.1"])
72
79
  s.add_dependency(%q<bundler>, ["~> 1.0"])
73
80
  s.add_dependency(%q<jeweler>, ["~> 2.0"])
@@ -81,6 +88,7 @@ Gem::Specification.new do |s|
81
88
  s.add_dependency(%q<actionpack>, ["~> 4.0"])
82
89
  s.add_dependency(%q<railties>, ["~> 4.0"])
83
90
  s.add_dependency(%q<flat_keys>, ["~> 0.0"])
91
+ s.add_dependency(%q<useragent>, ["~> 0.10"])
84
92
  s.add_dependency(%q<rdoc>, ["~> 4.1"])
85
93
  s.add_dependency(%q<bundler>, ["~> 1.0"])
86
94
  s.add_dependency(%q<jeweler>, ["~> 2.0"])
@@ -8,6 +8,6 @@ class ::BetterLogs::ActionController::Payload < DelegateClass(ActiveSupport::Has
8
8
  data[:controller] = data[:params].delete(:controller)
9
9
  data[:action] = data[:params].delete(:action)
10
10
  end
11
- super(data.flat_keys)
11
+ super(data.flat_keys('_'))
12
12
  end
13
13
  end
@@ -0,0 +1,13 @@
1
+ class ::BetterLogs::ActionDispatch::LogSubscriber < ActiveSupport::LogSubscriber
2
+ attr_reader :formatter, :logger
3
+
4
+ def initialize(formatter = ::BetterLogs::Formatters::KeyValueFormatter.new,
5
+ logger = ::Rails.logger)
6
+ @formatter = formatter
7
+ @logger = logger
8
+ end
9
+
10
+ def request(event)
11
+ logger.info formatter.format(::BetterLogs::ActionDispatch::Payload.new(event.payload))
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ class ::BetterLogs::ActionDispatch::Payload < DelegateClass(ActiveSupport::HashWithIndifferentAccess)
2
+ def initialize(payload)
3
+ request = payload[:request]
4
+ user_agent = UserAgent.parse(request.headers['HTTP_USER_AGENT'] || '')
5
+ data = {
6
+ remote_ip: request.remote_ip,
7
+ browser: {
8
+ name: user_agent.browser,
9
+ platform: user_agent.platform,
10
+ version: user_agent.version.to_s
11
+ }
12
+ }.flat_keys('_')
13
+ super(data)
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ module BetterLogs::ActionDispatch
2
+ end
@@ -1,5 +1,6 @@
1
1
  class ::BetterLogs::Initializer
2
2
  def self.initialize
3
3
  ::BetterLogs::ActionController::LogSubscriber.attach_to :action_controller
4
+ ::BetterLogs::ActionDispatch::LogSubscriber.attach_to :action_dispatch
4
5
  end
5
6
  end
data/lib/better_logs.rb CHANGED
@@ -2,6 +2,7 @@ module ::BetterLogs
2
2
  end
3
3
 
4
4
  require 'flat_keys'
5
+ require 'useragent'
5
6
  require 'rails'
6
7
  require 'active_support'
7
8
  require 'active_support/core_ext/hash/indifferent_access'
@@ -13,6 +14,10 @@ require_relative 'better_logs/action_controller'
13
14
  require_relative 'better_logs/action_controller/log_subscriber'
14
15
  require_relative 'better_logs/action_controller/payload'
15
16
 
17
+ require_relative 'better_logs/action_dispatch'
18
+ require_relative 'better_logs/action_dispatch/log_subscriber'
19
+ require_relative 'better_logs/action_dispatch/payload'
20
+
16
21
  require_relative 'better_logs/formatters'
17
22
  require_relative 'better_logs/formatters/key_value_formatter'
18
23
 
@@ -4,9 +4,9 @@ describe ::BetterLogs::ActionController::Payload do
4
4
  subject { ::BetterLogs::ActionController::Payload.new(payload) }
5
5
 
6
6
  describe 'when payload is a nested hash' do
7
- let(:payload) { {nested: {keys: {should: {be: {flattened: 'with dots'}}}}} }
7
+ let(:payload) { {nested: {keys: {should: {be: {flattened: 'with underscores'}}}}} }
8
8
  it 'flattens nested keys' do
9
- subject.should == { 'nested.keys.should.be.flattened' => 'with dots' }
9
+ subject.should == { 'nested_keys_should_be_flattened' => 'with underscores' }
10
10
  end
11
11
  end
12
12
 
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::BetterLogs::ActionDispatch::LogSubscriber do
4
+ context 'formatter' do
5
+ subject { described_class.new.formatter }
6
+
7
+ it "defaults to '#{::BetterLogs::Formatters::KeyValueFormatter.name}'" do
8
+ should be_an_instance_of ::BetterLogs::Formatters::KeyValueFormatter
9
+ end
10
+ end
11
+
12
+ context 'logger' do
13
+ before { Rails.stub(:logger).and_return(rails_logger) }
14
+ let(:rails_logger) { double(ActiveSupport::Logger) }
15
+ subject { described_class.new.logger }
16
+
17
+ it "defaults to 'Rails.logger'" do
18
+ should === rails_logger
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ describe ::BetterLogs::ActionDispatch::Payload do
3
+ let(:remote_ip) { '8.8.8.8' }
4
+ let(:headers) do
5
+ {'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36'}
6
+ end
7
+
8
+ let(:request) do
9
+ double(ActionDispatch::Request, remote_ip: remote_ip, headers: headers)
10
+ end
11
+
12
+ let(:payload) do
13
+ { request: request }
14
+ end
15
+
16
+ subject { OpenStruct.new(described_class.new(payload)) }
17
+
18
+ its(:remote_ip) { should == remote_ip }
19
+ its(:browser_name) { should == 'Chrome' }
20
+ its(:browser_platform) { should == 'Macintosh' }
21
+ its(:browser_version) { should == '34.0.1847.131' }
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_logs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kunal Parikh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-27 00:00:00.000000000 Z
11
+ date: 2014-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: useragent
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rdoc
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -171,7 +185,7 @@ executables: []
171
185
  extensions: []
172
186
  extra_rdoc_files:
173
187
  - LICENSE.txt
174
- - README.rdoc
188
+ - README.md
175
189
  files:
176
190
  - .coveralls.yml
177
191
  - .document
@@ -180,7 +194,7 @@ files:
180
194
  - Gemfile.lock
181
195
  - Guardfile
182
196
  - LICENSE.txt
183
- - README.rdoc
197
+ - README.md
184
198
  - Rakefile
185
199
  - VERSION
186
200
  - better_logs.gemspec
@@ -188,12 +202,17 @@ files:
188
202
  - lib/better_logs/action_controller.rb
189
203
  - lib/better_logs/action_controller/log_subscriber.rb
190
204
  - lib/better_logs/action_controller/payload.rb
205
+ - lib/better_logs/action_dispatch.rb
206
+ - lib/better_logs/action_dispatch/log_subscriber.rb
207
+ - lib/better_logs/action_dispatch/payload.rb
191
208
  - lib/better_logs/formatters.rb
192
209
  - lib/better_logs/formatters/key_value_formatter.rb
193
210
  - lib/better_logs/initializer.rb
194
211
  - lib/better_logs/railtie.rb
195
212
  - spec/lib/better_logs/action_controller/log_subscriber_spec.rb
196
213
  - spec/lib/better_logs/action_controller/payload_spec.rb
214
+ - spec/lib/better_logs/action_dispatch/log_subscriber_spec.rb
215
+ - spec/lib/better_logs/action_dispatch/payload_spec.rb
197
216
  - spec/lib/better_logs/formatters/key_value_formatter_spec.rb
198
217
  - spec/spec_helper.rb
199
218
  homepage: http://github.com/techthumb/better_logs
@@ -216,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
235
  version: '0'
217
236
  requirements: []
218
237
  rubyforge_project:
219
- rubygems_version: 2.2.1
238
+ rubygems_version: 2.2.2
220
239
  signing_key:
221
240
  specification_version: 4
222
241
  summary: Better logging for Rails request/response lifecycle.
data/README.rdoc DELETED
@@ -1,22 +0,0 @@
1
- {<img src="https://travis-ci.org/techthumb/better_logs.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/techthumb/better_logs]
2
- {<img src="https://badge.fury.io/rb/better_logs.svg" alt="Gem Version" />}[http://badge.fury.io/rb/better_logs]
3
- {<img src="https://codeclimate.com/repos/535a5dcae30ba03fdc00efe2/badges/1196b8f5d38c79f87546/gpa.png" />}[https://codeclimate.com/repos/535a5dcae30ba03fdc00efe2/feed]
4
- {<img src="https://codeclimate.com/repos/535a5dcae30ba03fdc00efe2/badges/1196b8f5d38c79f87546/coverage.png" />}[https://codeclimate.com/repos/535a5dcae30ba03fdc00efe2/feed]
5
- = BetterLogs
6
-
7
- Logging for Rails request/response lifecycle in a machine readable format (starting with Splunk) — Edit
8
-
9
- == Contributing
10
-
11
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
12
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
13
- * Fork the project.
14
- * Start a feature/bugfix branch.
15
- * Commit and push until you are happy with your contribution.
16
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
17
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
18
-
19
- == Copyright
20
-
21
- Copyright (c) 2014 Kunal Parikh. See LICENSE.txt for
22
- further details.