active_support-custom_logger 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c4787987fbe6abdf3fbd3467ca31706c08ba37e5
4
+ data.tar.gz: faa9eadaf0f1a65e2e45927c5811089ad05f3701
5
+ SHA512:
6
+ metadata.gz: 15ed3b73faad578df613841b105e31ee45b565df3f8267a6a2eb386a6b9f0ea7a88ec75b628e15dd71ab885fe6b5c36ac416c6f48d1eeb4a7a84bfd373e3e419
7
+ data.tar.gz: f96d2ca38517235c03149e7b1c51a9e80f92945e1f43cb1119b80af7833fdb672f871f60467d0648f625af80225d1f8c08fdca4705fea7ddbf565b330ceaf1e3
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_support-custom_logger.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Aaron Wallis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # ActiveSupport::CustomLogger
2
+
3
+ Adds timestamp, request UUID and parent Process ID to each line of the Rails logger. Works on Rails 3.x & 4.x.
4
+
5
+ ```
6
+ [2014-09-17T16:33:48] [663a7b21] [85324] Started GET "/" for 127.0.0.1 at 2014-09-17 16:33:48 -0700
7
+ [2014-09-17T16:33:48] [663a7b21] [85324] Processing by RootController#index as HTML
8
+ [2014-09-17T16:33:49] [663a7b21] [85324] Rendered root/index.html.haml within layouts/application (0.1ms)
9
+ [2014-09-17T16:33:49] [663a7b21] [85324] Completed 200 OK in 28ms (Views: 27.4ms | ActiveRecord: 0.0ms)
10
+ ```
11
+
12
+ Rails' Tagged Logging works for most cases, but for anything that needs to evaluate more than once per request (like a timestamp) log tags are insufficient. Custom Logger alias_method_chain's methods in ActiveSupport's BufferedLogger (Rails 3.x) or SimpleFormatter (Rails 4.x) in order to get a timestamp on each line in the log.
13
+
14
+ These three items are currently not configurable as it's version 0.0.1 and I'm making this for internal B/R use.
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'active_support-custom_logger'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install active_support-custom_logger
31
+
32
+ ## TODO
33
+
34
+ Specs.
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( https://github.com/[my-github-username]/active_support-custom_logger/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_support/custom_logger'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_support-custom_logger"
8
+ spec.version = ActiveSupport::CustomLogger::VERSION
9
+ spec.authors = ["Aaron Wallis"]
10
+ spec.email = ["awallis@bleacherreport.com"]
11
+ spec.summary = %q{Custom Rails Logger}
12
+ spec.description = %q{Add timestamps, parent PID's and request UUID's to each logger line.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "activesupport", ">= 3.0.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,51 @@
1
+ require 'active_support/version'
2
+ require 'active_support/core_ext/module/aliasing'
3
+
4
+ module ActiveSupport
5
+ class CustomLogger
6
+ module InstanceMethods
7
+ def formatted_timestamp
8
+ "[#{Time.now.strftime('%FT%T')}]"
9
+ end
10
+ end
11
+ end
12
+
13
+ if ActiveSupport::VERSION::MAJOR == 3
14
+
15
+ require 'active_support/buffered_logger'
16
+
17
+ class BufferedLogger
18
+ include CustomLogger::InstanceMethods
19
+
20
+ def add_with_formatted_timestamp(severity, message = nil, progname = nil, &block)
21
+ add_without_formatted_timestamp(severity, "#{formatted_timestamp} #{message}", progname, &block)
22
+ end
23
+
24
+ alias_method_chain :add, :formatted_timestamp
25
+ end
26
+
27
+ elsif ActiveSupport::VERSION::MAJOR >= 4
28
+
29
+ require 'active_support/logger'
30
+
31
+ class Logger < ::Logger
32
+ class SimpleFormatter < ::Logger::Formatter
33
+ include CustomLogger::InstanceMethods
34
+
35
+ def call_with_formatted_timestamp(severity, timestamp, progname, msg)
36
+ msg = "#{formatted_timestamp} #{msg}" if String === msg
37
+ call_without_formatted_timestamp(severity, timestamp, progname, msg)
38
+ end
39
+
40
+ alias_method_chain :call, :formatted_timestamp
41
+ end
42
+ end
43
+
44
+ else
45
+ raise "Requires ActiveSupport >= 3"
46
+ end
47
+ end
48
+
49
+ ActiveSupport::CustomLogger.const_set(:VERSION, "0.0.1")
50
+
51
+ require_relative 'custom_logger/railtie' if defined?(Rails::Railtie)
@@ -0,0 +1,12 @@
1
+ module ActiveSupport
2
+ class CustomLogger
3
+ class Railtie < Rails::Railtie
4
+ initializer "before_initialize" do |app|
5
+ app.config.log_tags = [
6
+ lambda { |r| r.uuid[0..7] },
7
+ lambda { |r| Process.pid }
8
+ ]
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveSupport::CustomLogger do
4
+ it 'has a version number' do
5
+ expect(ActiveSupport::CustomLogger::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'active_support/custom_logger'
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_support-custom_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Wallis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
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
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Add timestamps, parent PID's and request UUID's to each logger line.
70
+ email:
71
+ - awallis@bleacherreport.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - .travis.yml
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - active_support-custom_logger.gemspec
84
+ - lib/active_support/custom_logger.rb
85
+ - lib/active_support/custom_logger/railtie.rb
86
+ - spec/active_support/custom_logger_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: ''
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.0.14
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Custom Rails Logger
112
+ test_files:
113
+ - spec/active_support/custom_logger_spec.rb
114
+ - spec/spec_helper.rb