rails_oneline_logging 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5c2889e15b682f832a1a23f309402dbffa02172e
4
+ data.tar.gz: 72277f49c03ee52417f64d6edde7a37f1c916138
5
+ SHA512:
6
+ metadata.gz: 34f99ef274e4707a3942aa4a5827a03853788deb3807b07f3c63d6d7a9f265fea84d6697faa8fa6b01c4a6c36bbdd9a9b5cd1204d318942840970ee5c9de7fb6
7
+ data.tar.gz: 8cbf0b2639ab0e3e1342e9a02c4c0cd666a6e347ccfe440e6b97e3bad9d0a8457f14de392c8fc14868907f227c3e9f98446282f11520eb913802b3c71980f898
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ tmp/*
5
+ coverage/*
6
+ *.gem
7
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in dobt_auth.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Department of Better Technology, Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ Rails "Oneline" Logging
2
+ ====
3
+
4
+ All credit to https://gist.github.com/troy/3310392.
5
+
6
+ ## Usage
7
+
8
+ ```ruby
9
+ # Gemfile
10
+ gem 'rails_oneline_logging'
11
+ ```
12
+
13
+ ```ruby
14
+ # config/environments/*.rb
15
+ Rails.application.configure do
16
+ config.log_level = :warn
17
+ end
18
+ ```
@@ -0,0 +1,64 @@
1
+ module RailsOnelineLogging
2
+ class Railtie < ::Rails::Railtie
3
+ initializer 'rails_oneline_logging' do |app|
4
+ # Outputs this at warn log level:
5
+ # 1.2.3.4 GET /path 200 OK BlahController#action HTML 938.2 (DB 11.8, View 719.7) {params} {optional params from flash[:log]}
6
+ #
7
+ # Consider decreasing the log level from "info" to "warn" (in production.rb) so
8
+ # the one-line log message replaces the standard request logs.
9
+
10
+ # override process_action to add 2 things to the payload:
11
+ # - remote IP
12
+ # - an optional stash which is available to subscribers. Basically, flash[:log].inspect will be logged.
13
+ # 3.0: https://github.com/rails/rails/blob/3-0-stable/actionpack/lib/action_controller/metal/instrumentation.rb
14
+ # 3.1: https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/instrumentation.rb
15
+ ActionController::Instrumentation.send(:define_method, "process_action") do |arg|
16
+ raw_payload = {
17
+ :controller => self.class.name,
18
+ :action => self.action_name,
19
+ # https://github.com/tenderlove/the_metal/issues/8
20
+ :params => (request.filtered_parameters rescue {}),
21
+ :formats => request.formats.map(&:to_sym),
22
+ :method => request.method,
23
+ :path => (request.fullpath rescue "unknown"),
24
+
25
+ :ip => request.remote_ip,
26
+ :stash => request.session['flash'] && request.session['flash'][:log]
27
+ }
28
+
29
+ ActiveSupport::Notifications.instrument("start_processing.action_controller", raw_payload.dup)
30
+
31
+ ActiveSupport::Notifications.instrument("process_action.action_controller", raw_payload) do |payload|
32
+ result = super(arg)
33
+ payload[:status] = response.status
34
+ append_info_to_payload(payload)
35
+ result
36
+ end
37
+ end
38
+
39
+ ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, start, finish, id, payload|
40
+ # borrows from
41
+ # https://github.com/rails/rails/blob/3-0-stable/actionpack/lib/action_controller/log_subscriber.rb
42
+ params = payload[:params].except('controller', 'action', 'format', '_method', 'only_path')
43
+
44
+ format = payload[:formats].first.to_s.upcase
45
+ duration = (finish-start)*1000
46
+
47
+ status = payload[:status]
48
+ if status.nil? && payload[:exception].present?
49
+ # 3.1: http://rubydoc.info/docs/rails/3.1.1/ActionController/LogSubscriber#process_action-instance_method
50
+ status = Rack::Utils.status_code(ActionDispatch::ShowExceptions.rescue_responses[payload[:exception].first]) rescue nil
51
+ end
52
+
53
+ m = "%s %s %s %s %s %s\#%s %s %.1f (DB %.1f, View %.1f) %s %s" % [
54
+ payload[:ip], payload[:method], payload[:path],
55
+ status, Rack::Utils::HTTP_STATUS_CODES[status],
56
+ payload[:controller], payload[:action], format,
57
+ duration || 0, payload[:db_runtime] || 0, payload[:view_runtime] || 0,
58
+ params.inspect, payload[:stash].try(:inspect) || {}.inspect ]
59
+
60
+ Rails.logger.warn(m)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ module RailsOnelineLogging
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,24 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "rails_oneline_logging/version"
5
+
6
+ Gem::Specification.new do |s|
7
+
8
+ s.name = "rails_oneline_logging"
9
+ s.summary = 'One-line detailed logging for Rails 3+.'
10
+ s.version = RailsOnelineLogging::VERSION
11
+
12
+ s.authors = ['Adam Becker']
13
+ s.email = 'adam@dobt.co'
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {features,spec}/*`.split("\n")
18
+
19
+ s.homepage = 'http://github.com/dobtco/rails_oneline_logging'
20
+ s.require_paths = ['lib']
21
+
22
+ s.add_dependency 'rails'
23
+
24
+ end
data/script/release ADDED
@@ -0,0 +1,38 @@
1
+ #!/bin/sh
2
+ # Tag and push a release.
3
+
4
+ set -e
5
+
6
+ # Make sure we're in the project root.
7
+
8
+ cd $(dirname "$0")/..
9
+
10
+ # Build a new gem archive.
11
+
12
+ rm -rf rails_oneline_logging-*.gem
13
+ gem build -q rails_oneline_logging.gemspec
14
+
15
+ # Make sure we're on the master branch.
16
+
17
+ (git branch | grep -q '* master') || {
18
+ echo "Only release from the master branch."
19
+ exit 1
20
+ }
21
+
22
+ # Figure out what version we're releasing.
23
+
24
+ tag=v`ls rails_oneline_logging-*.gem | sed 's/^rails_oneline_logging-\(.*\)\.gem$/\1/'`
25
+
26
+ # Make sure we haven't released this version before.
27
+
28
+ git fetch -t origin
29
+
30
+ (git tag -l | grep -q "$tag") && {
31
+ echo "Whoops, there's already a '${tag}' tag."
32
+ exit 1
33
+ }
34
+
35
+ # Tag it and bag it.
36
+
37
+ gem push rails_oneline_logging-*.gem && git tag "$tag" &&
38
+ git push origin master && git push origin "$tag"
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_oneline_logging
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adam Becker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email: adam@dobt.co
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".gitignore"
34
+ - Gemfile
35
+ - LICENSE.md
36
+ - README.md
37
+ - lib/rails_oneline_logging.rb
38
+ - lib/rails_oneline_logging/version.rb
39
+ - rails_oneline_logging.gemspec
40
+ - script/release
41
+ homepage: http://github.com/dobtco/rails_oneline_logging
42
+ licenses:
43
+ - MIT
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.2.2
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: One-line detailed logging for Rails 3+.
65
+ test_files: []
66
+ has_rdoc: