lograge 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format progress
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.0
6
- script: bundle exec rspec
data/CHANGES.md DELETED
@@ -1,11 +0,0 @@
1
- ### 0.3.0
2
-
3
- * #47: Add formatter for l2met (<https://github.com/BRMatt>)
4
-
5
- * #55: Update Logstash formatter for Logstash 1.2 format (<https://github.com/msaffitz>)
6
-
7
- * #56: Add JSON formatter (<https://github.com/i0rek>)
8
-
9
- * #59: Add `before_format` hook (<https://github.com/i0rek>)
10
-
11
- * #60: Add Ruby 2.1.0 for testing on Travis CI (<https://github.com/salimane>)
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in lograge.gemspec
4
- gemspec
5
-
6
- group :test do
7
- gem 'actionpack'
8
- gem 'logstash-event', '1.1.5'
9
- end
data/Guardfile DELETED
@@ -1,9 +0,0 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
- guard 'rspec', :version => 2 do
5
- watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
- watch('spec/spec_helper.rb') { "spec" }
8
- end
9
-
data/README.md DELETED
@@ -1,235 +0,0 @@
1
- Lograge - Taming Rails' Default Request Logging
2
- =======
3
-
4
- Lograge is an attempt to bring sanity to Rails' noisy and unusable, unparsable
5
- and, in the context of running multiple processes and servers, unreadable
6
- default logging output. Rails' default approach to log everything is great
7
- during development, it's terrible when running it in production. It pretty much
8
- renders Rails logs useless to me.
9
-
10
- Lograge is a work in progress. I appreciate constructive feedback and criticism.
11
- My main goal is to improve Rails' logging and to show people that they don't
12
- need to stick with its defaults anymore if they don't want to.
13
-
14
- Instead of trying solving the problem of having multiple lines per request by
15
- switching Rails' logger for something that outputs syslog lines or adds a
16
- request token, Lograge replaces Rails' request logging entirely, reducing the
17
- output per request to a single line with all the important information, removing
18
- all that clutter Rails likes to include and that gets mingled up so nicely when
19
- multiple processes dump their output into a single file.
20
-
21
- Instead of having an unparsable amount of logging output like this:
22
-
23
- ```
24
- Started GET "/" for 127.0.0.1 at 2012-03-10 14:28:14 +0100
25
- Processing by HomeController#index as HTML
26
- Rendered text template within layouts/application (0.0ms)
27
- Rendered layouts/_assets.html.erb (2.0ms)
28
- Rendered layouts/_top.html.erb (2.6ms)
29
- Rendered layouts/_about.html.erb (0.3ms)
30
- Rendered layouts/_google_analytics.html.erb (0.4ms)
31
- Completed 200 OK in 79ms (Views: 78.8ms | ActiveRecord: 0.0ms)
32
- ```
33
-
34
- you get a single line with all the important information, like this:
35
-
36
- ```
37
- method=GET path=/jobs/833552.json format=json controller=jobs action=show status=200 duration=58.33 view=40.43 db=15.26
38
- ```
39
-
40
- The second line is easy to grasp with a single glance and still includes all the
41
- relevant information as simple key-value pairs. The syntax is heavily inspired
42
- by the log output of the Heroku router. It doesn't include any timestamp by
43
- default, instead it assumes you use a proper log formatter instead.
44
-
45
- **Installation**
46
-
47
- In your Gemfile
48
-
49
- ```ruby
50
- gem "lograge"
51
- ```
52
-
53
- Enable it for the relevant environments, e.g. production:
54
-
55
- ```ruby
56
- # config/environments/production.rb
57
- MyApp::Application.configure do
58
- config.lograge.enabled = true
59
- end
60
- ```
61
-
62
- You can also add a hook for own custom data
63
-
64
- ```ruby
65
- # config/environments/staging.rb
66
- MyApp::Application.configure do
67
- config.lograge.enabled = true
68
-
69
- # custom_options can be a lambda or hash
70
- # if it's a lambda then it must return a hash
71
- config.lograge.custom_options = lambda do |event|
72
- # capture some specific timing values you are interested in
73
- {:name => "value", :timing => some_float.round(2), :host => event.payload[:host]}
74
- end
75
- end
76
- ```
77
-
78
- Or you can add a timestamp:
79
-
80
- ```ruby
81
- MyApp::Application.configure do
82
- config.lograge.enabled = true
83
-
84
- # add time to lograge
85
- config.lograge.custom_options = lambda do |event|
86
- {:time => event.time}
87
- end
88
- end
89
- ```
90
-
91
- You can then add custom variables to the event to be used in custom_options
92
-
93
- ```ruby
94
- # app/controllers/application_controller.rb
95
- class ApplicationController < ActionController::Base
96
- def append_info_to_payload(payload)
97
- super
98
- payload[:host] = request.host
99
- end
100
- end
101
- ```
102
-
103
- To further clean up your logging, you can also tell Lograge to skip log messages
104
- meeting given criteria. You can skip log messages generated from certain controller
105
- actions, or you can write a custom handler to skip messages based on data in the log event:
106
-
107
- ```ruby
108
- # config/environments/production.rb
109
- MyApp::Application.configure do
110
- config.lograge.enabled = true
111
-
112
- config.lograge.ignore_actions = ['home#index', 'aController#anAction']
113
- config.lograge.ignore_custom = lambda do |event|
114
- # return true here if you want to ignore based on the event
115
- end
116
- end
117
- ```
118
-
119
- Lograge supports multiple output formats. The most common is the default
120
- lograge key-value format described above. Alternatively, you can also generate
121
- JSON logs in the json_event format used by [Logstash](http://logstash.net/).
122
-
123
- ```ruby
124
- # config/environments/production.rb
125
- MyApp::Application.configure do
126
- config.lograge.formatter = Lograge::Formatters::Logstash.new
127
- end
128
- ```
129
-
130
- *Note:* When using the logstash output, you need to add the additional gem
131
- `logstash-event`. You can simply add it to your Gemfile like this
132
-
133
- ```ruby
134
- gem "logstash-event"
135
- ```
136
-
137
- Done.
138
-
139
- The available formatters are:
140
-
141
- ```ruby
142
- Lograge::Formatters::Cee.new
143
- Lograge::Formatters::Graylog2.new
144
- Lograge::Formatters::KeyValue.new # default lograge format
145
- Lograge::Formatters::Logstash.new
146
- Lograge::Formatters::Raw.new # Returns a ruby hash object
147
- ```
148
-
149
- In addition to the formatters, you can manipulate the data your self by passing
150
- an object which responds to #call:
151
-
152
- ```ruby
153
- # config/environments/production.rb
154
- MyApp::Application.configure do
155
- config.lograge.formatter = ->(data) { "Called #{data[:controller]}" } # data is a ruby hash
156
- end
157
- ```
158
-
159
- **Internals**
160
-
161
- Thanks to the notification system that was introduced in Rails 3, replacing the
162
- logging is easy. Lograge unhooks all subscriptions from
163
- `ActionController::LogSubscriber` and `ActionView::LogSubscriber`, and hooks in
164
- its own log subscription, but only listening for two events: `process_action`
165
- and `redirect_to`. It makes sure that only subscriptions from those two classes
166
- are removed. If you happened to hook in your own, they'll be safe.
167
-
168
- Unfortunately, when a redirect is triggered by your application's code,
169
- ActionController fires two events. One for the redirect itself, and another one
170
- when the request is finished. Unfortunately the final event doesn't include the
171
- redirect, so Lograge stores the redirect URL as a thread-local attribute and
172
- refers to it in `process_action`.
173
-
174
- The event itself contains most of the relevant information to build up the log
175
- line, including view processing and database access times.
176
-
177
- While the LogSubscribers encapsulate most logging pretty nicely, there are still
178
- two lines that show up no matter what. The first line that's output for every
179
- Rails request, you know, this one:
180
-
181
- ```
182
- Started GET "/" for 127.0.0.1 at 2012-03-12 17:10:10 +0100
183
- ```
184
-
185
- And the verbose output coming from rack-cache:
186
-
187
- ```
188
- cache: [GET /] miss
189
- ```
190
-
191
- Both are independent of the LogSubscribers, and both need to be shut up using
192
- different means.
193
-
194
- For the first one, the starting line of every Rails request log, Lograge
195
- replaces code in `Rails::Rack::Logger` to remove that particular log line. It's
196
- not great, but it's just another unnecessary output and would still clutter the
197
- log files. Maybe a future version of Rails will make this log line an event as
198
- well.
199
-
200
- To remove rack-cache's output (which is only enabled if caching in Rails is
201
- enabled), Lograge disables verbosity for rack-cache, which is unfortunately
202
- enabled by default.
203
-
204
- There, a single line per request. Beautiful.
205
-
206
- **What it doesn't do**
207
-
208
- Lograge is opinionated, very opinionated. If the stuff below doesn't suit your
209
- needs, it may not be for you.
210
-
211
- Lograge removes ActionView logging, which also includes rendering times for
212
- partials. If you're into those, Lograge is probably not for you. In my honest
213
- opinion, those rendering times don't belong in the log file, they should be
214
- collected in a system like New Relic, Librato Metrics or some other metrics
215
- service that allows graphing rendering percentiles. I assume this for everything
216
- that represents a moving target. That kind of data is better off being
217
- visualized in graphs than dumped (and ignored) in a log file.
218
-
219
- Lograge doesn't yet log the request parameters. This is something I'm actively
220
- contemplating, mainly because I want to find a good way to include them, a way
221
- that fits in with the general spirit of the log output generated by Lograge.
222
-
223
- **Changes**
224
-
225
- * Add support for Graylog2 events (Lennart Koopmann, http://github.com/lennartkoopmann)
226
- * Add support for Logstash events (Holger Just, http://github.com/meineerde)
227
- * Fix for Rails 3.2.9
228
- * Use keys everywhere (Curt Michols, http://github.com/asenchi)
229
- * Add `custom_options` to allow adding custom key-value pairs at runtime (Adam
230
- Cooper, https://github.com/adamcooper)
231
-
232
- **License**
233
-
234
- MIT. Code extracted from [Travis CI](http://travis-ci.org).
235
- (c) 2012 Mathias Meyer
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"
data/lograge.gemspec DELETED
@@ -1,27 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "lograge/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "lograge"
7
- s.version = Lograge::VERSION
8
- s.authors = ["Mathias Meyer"]
9
- s.email = ["meyer@paperplanes.de"]
10
- s.homepage = "https://github.com/roidrage/lograge"
11
- s.summary = %q{Tame Rails' multi-line logging into a single line per request}
12
- s.description = %q{Tame Rails' multi-line logging into a single line per request}
13
-
14
- s.rubyforge_project = "lograge"
15
-
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
20
-
21
- # specify any dependencies here; for example:
22
- s.add_development_dependency "rspec"
23
- s.add_development_dependency "guard-rspec"
24
- s.add_runtime_dependency "activesupport", '>= 3'
25
- s.add_runtime_dependency "actionpack", '>= 3'
26
- s.add_runtime_dependency "railties", '>= 3'
27
- end
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
- require 'lograge'
3
-
4
- describe Lograge::Formatters::Cee do
5
- it { expect( subject.call({})).to match(/^@cee/) }
6
- it { expect(subject.call({ custom: 'data'})).to match('{"custom":"data"}') }
7
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
- require 'lograge'
3
-
4
- describe Lograge::Formatters::Graylog2 do
5
- let(:payload) do
6
- {
7
- custom: 'data',
8
- status: 200,
9
- method: 'GET',
10
- path: '/',
11
- controller: 'welcome',
12
- action: 'index'
13
- }
14
- end
15
- subject { described_class.new.call(payload) }
16
- it { expect(subject[:_custom]).to eq('data') }
17
- it { expect(subject[:short_message]).to eq('[200] GET / (welcome#index)') }
18
- end
@@ -1,6 +0,0 @@
1
- require 'spec_helper'
2
- require 'lograge'
3
-
4
- describe Lograge::Formatters::Json do
5
- it { expect( subject.call({ custom: 'data' })).to eq('{"custom":"data"}') }
6
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
- require 'lograge'
3
-
4
- describe Lograge::Formatters::KeyValue do
5
- let(:payload) do
6
- {
7
- custom: 'data',
8
- status: 200,
9
- method: 'GET',
10
- path: '/',
11
- controller: 'welcome',
12
- action: 'index'
13
- }
14
- end
15
-
16
- subject { described_class.new.call(payload) }
17
-
18
- it { should include('controller=welcome') }
19
- it { should include('action=index') }
20
-
21
- it_behaves_like "a key value formatter"
22
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
- require 'lograge'
3
-
4
- describe Lograge::Formatters::L2met do
5
- let(:payload) do
6
- {
7
- custom: 'data',
8
- status: 200,
9
- method: 'GET',
10
- path: '/',
11
- controller: 'admin/welcome',
12
- action: 'index',
13
- db: 20.00,
14
- view: 10.00,
15
- duration: 30.00,
16
- cache: 40.00
17
- }
18
- end
19
-
20
- it_behaves_like "a key value formatter"
21
-
22
- subject { described_class.new.call(payload) }
23
-
24
- it { should include('source=admin-welcome:index') }
25
- it { should_not include('controller=admin/welcome') }
26
- it { should_not include('action=index') }
27
- it { should include('measure#page.duration=30.00') }
28
- it { should include('measure#page.view=10.00') }
29
- it { should include('measure#page.db=20.00') }
30
- it { should include('measure#page.cache=40.00') }
31
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
- require 'lograge'
3
-
4
- describe Lograge::Formatters::Logstash do
5
- let(:payload) do
6
- {
7
- custom: 'data',
8
- status: 200,
9
- method: 'GET',
10
- path: '/',
11
- controller: 'welcome',
12
- action: 'index'
13
- }
14
- end
15
- subject { described_class.new.call(payload) }
16
- it { should match(/"custom":"data"/) }
17
- it { should match(/"status":200/) }
18
- it { should match(/"method":"GET"/) }
19
- it { should match(/"path":"\/"/) }
20
- it { should match(/"controller":"welcome"/) }
21
- it { should match(/"action":"index"/) }
22
- end
@@ -1,6 +0,0 @@
1
- require 'spec_helper'
2
- require 'lograge'
3
-
4
- describe Lograge::Formatters::Raw do
5
- it { expect( subject.call({ custom: 'data' })).to eq({ custom: 'data' }) }
6
- end