rails-flog 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +18 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +107 -0
- data/Rakefile +8 -0
- data/gemfiles/activemodel_3_2_x.gemfile +7 -0
- data/gemfiles/activemodel_4_0_x.gemfile +7 -0
- data/lib/flog.rb +5 -0
- data/lib/flog/params_formattable.rb +39 -0
- data/lib/flog/payload_value_shuntable.rb +19 -0
- data/lib/flog/sql_formattable.rb +31 -0
- data/lib/flog/version.rb +4 -0
- data/rails-flog.gemspec +29 -0
- data/test/test_helper.rb +42 -0
- data/test/unit/params_formattable_test.rb +72 -0
- data/test/unit/payload_value_shuntable_test.rb +57 -0
- data/test/unit/sql_formattable_test.rb +63 -0
- metadata +165 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c2e219154b03727ea2a4b7f3fb3ae97258085dbe
|
4
|
+
data.tar.gz: 8e87fe2fc6ce0ed022482168d7776b3e5f8e1c24
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e6510bf8585735c1ddf0af141c922ef804f295d88e7efc66975d259f285c9cbb35b0935958889647ac24cf5c107bbdc7a0da8223404cb9232aeba89bf1f38ac0
|
7
|
+
data.tar.gz: cbab9d2ade5b65ecd88cf05b92ddd6aaf80b52cddb09b58c3caa9be2a17b0f2a121ca28e80b966c166cfca13ffd459d6878e13d7e87caf510f88a7d00f0ec898
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 pinzolo
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# rails-flog
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/pinzolo/rails-flog.png)](http://travis-ci.org/pinzolo/rails-flog)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/pinzolo/rails-flog/badge.png)](https://coveralls.io/r/pinzolo/rails-flog)
|
5
|
+
|
6
|
+
rails-flog provides feature that formats parameters Hash and SQL in Rails log file.
|
7
|
+
|
8
|
+
## Before and after (Sampla app: Redmine)
|
9
|
+
|
10
|
+
### Before (Default)
|
11
|
+
|
12
|
+
```
|
13
|
+
# Parameters
|
14
|
+
Processing by IssuesController#create as HTML
|
15
|
+
Parameters: {"utf8"=>"✓", "authenticity_token"=>"VYCWAsE+aAN+zSZq2H3ONNqaU8rlyfbnXLfbwDY1i10=", "issue"=>{"is_private"=>"0", "tracker_id"=>"1", "subject"=>"test ticket", "description"=>"test ticket description", "status_id"=>"1", "priority_id"=>"2", "assigned_to_id"=>"1", "parent_issue_id"=>"", "start_date"=>"2013-11-28", "due_date"=>"2013-11-29", "estimated_hours"=>"5", "done_ratio"=>"10"}, "commit"=>"Create", "project_id"=>"test"}
|
16
|
+
|
17
|
+
# SQL
|
18
|
+
IssueCustomField Load (0.0ms) SELECT "custom_fields".* FROM "custom_fields" WHERE "custom_fields"."type" IN ('IssueCustomField') AND (is_for_all = 't' OR id IN (SELECT DISTINCT cfp.custom_field_id FROM custom_fields_projects cfp WHERE cfp.project_id = 1)) ORDER BY custom_fields.position ASC
|
19
|
+
```
|
20
|
+
|
21
|
+
### After (Use rails-flog)
|
22
|
+
|
23
|
+
```
|
24
|
+
# Parameters
|
25
|
+
Processing by IssuesController#create as HTML
|
26
|
+
Parameters:
|
27
|
+
{
|
28
|
+
"utf8" => "✓",
|
29
|
+
"authenticity_token" => "VYCWAsE+aAN+zSZq2H3ONNqaU8rlyfbnXLfbwDY1i10=",
|
30
|
+
"issue" => {
|
31
|
+
"is_private" => "0",
|
32
|
+
"tracker_id" => "1",
|
33
|
+
"subject" => "test ticket",
|
34
|
+
"description" => "test ticket description",
|
35
|
+
"status_id" => "1",
|
36
|
+
"priority_id" => "2",
|
37
|
+
"assigned_to_id" => "1",
|
38
|
+
"parent_issue_id" => "",
|
39
|
+
"start_date" => "2013-11-28",
|
40
|
+
"due_date" => "2013-11-29",
|
41
|
+
"estimated_hours" => "5",
|
42
|
+
"done_ratio" => "10"
|
43
|
+
},
|
44
|
+
"commit" => "Create",
|
45
|
+
"project_id" => "test"
|
46
|
+
}
|
47
|
+
|
48
|
+
# SQL
|
49
|
+
IssueCustomField Load (0.0ms)
|
50
|
+
SELECT
|
51
|
+
"custom_fields" . *
|
52
|
+
FROM
|
53
|
+
"custom_fields"
|
54
|
+
WHERE
|
55
|
+
"custom_fields" . "type" IN ('IssueCustomField')
|
56
|
+
AND (
|
57
|
+
is_for_all = 't'
|
58
|
+
OR id IN (
|
59
|
+
SELECT
|
60
|
+
DISTINCT cfp.custom_field_id
|
61
|
+
FROM
|
62
|
+
custom_fields_projects cfp
|
63
|
+
WHERE
|
64
|
+
cfp.project_id = 1
|
65
|
+
)
|
66
|
+
)
|
67
|
+
ORDER BY
|
68
|
+
custom_fields.position ASC
|
69
|
+
```
|
70
|
+
|
71
|
+
## Installation
|
72
|
+
|
73
|
+
Add this line to your application's Gemfile:
|
74
|
+
(Recommendation: use only `:development` and `:test` enviroment)
|
75
|
+
|
76
|
+
gem 'rails-flog', :require => "flog"
|
77
|
+
|
78
|
+
And then execute:
|
79
|
+
|
80
|
+
$ bundle
|
81
|
+
|
82
|
+
Or install it yourself as:
|
83
|
+
|
84
|
+
$ gem install rails-flog
|
85
|
+
|
86
|
+
## Usage
|
87
|
+
|
88
|
+
Just install.
|
89
|
+
|
90
|
+
## Supported versions
|
91
|
+
|
92
|
+
- Ruby: 1.9.3, 2.0.0
|
93
|
+
- Rails: 3.2.x, 4.0.x
|
94
|
+
|
95
|
+
## Contributing
|
96
|
+
|
97
|
+
1. Fork it
|
98
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
99
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
100
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
101
|
+
5. Create new Pull Request
|
102
|
+
|
103
|
+
## Thanks
|
104
|
+
|
105
|
+
- [awesome_print](https://github.com/michaeldv/awesome_print) : Use format Hash
|
106
|
+
- [anbt-sql-formatter](https://github.com/sonota/anbt-sql-formatter) : Use format SQL
|
107
|
+
- [yuroyoro](http://yuroyoro.hatenablog.com/entry/2013/04/12/141648) : Inspired
|
data/Rakefile
ADDED
data/lib/flog.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "action_controller/log_subscriber"
|
3
|
+
require "awesome_print"
|
4
|
+
require "flog/payload_value_shuntable"
|
5
|
+
|
6
|
+
class ActionController::LogSubscriber
|
7
|
+
include PayloadValueShuntable
|
8
|
+
|
9
|
+
alias :original_start_processing :start_processing
|
10
|
+
|
11
|
+
def start_processing(event)
|
12
|
+
replaced = replace_params(event.payload[:params])
|
13
|
+
|
14
|
+
shunt_payload_value(event.payload, :params, replaced) do
|
15
|
+
original_start_processing(event)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def replace_params(params)
|
21
|
+
return params if params.empty? || !params.respond_to?(:ai)
|
22
|
+
|
23
|
+
replaced = params.dup
|
24
|
+
class << replaced
|
25
|
+
alias :original_except :except
|
26
|
+
|
27
|
+
def except(*keys)
|
28
|
+
excepted = original_except(*keys)
|
29
|
+
class << excepted
|
30
|
+
def inspect
|
31
|
+
"\n#{ai(plain: !ActionController::LogSubscriber.colorize_logging)}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
excepted
|
35
|
+
end
|
36
|
+
end
|
37
|
+
replaced
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module PayloadValueShuntable
|
3
|
+
def shunt_payload_value(payload, key, temp_value, &block)
|
4
|
+
return unless block
|
5
|
+
|
6
|
+
key_exists = payload.key?(key)
|
7
|
+
base_value = payload[key]
|
8
|
+
begin
|
9
|
+
payload[key] = temp_value
|
10
|
+
block.call
|
11
|
+
ensure
|
12
|
+
if key_exists
|
13
|
+
payload[key] = base_value
|
14
|
+
else
|
15
|
+
payload.delete(key)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "active_record/log_subscriber"
|
3
|
+
require "flog/payload_value_shuntable"
|
4
|
+
|
5
|
+
class ActiveRecord::LogSubscriber
|
6
|
+
include PayloadValueShuntable
|
7
|
+
|
8
|
+
alias :original_sql :sql
|
9
|
+
|
10
|
+
def sql(event)
|
11
|
+
formatted = format_sql(event.payload[:sql])
|
12
|
+
|
13
|
+
shunt_payload_value(event.payload, :sql, "\n\t#{formatted}") do
|
14
|
+
original_sql(event)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def format_sql(sql)
|
20
|
+
return sql if sql.blank?
|
21
|
+
|
22
|
+
require "anbt-sql-formatter/formatter"
|
23
|
+
rule = AnbtSql::Rule.new
|
24
|
+
rule.keyword = AnbtSql::Rule::KEYWORD_UPPER_CASE
|
25
|
+
%w(count sum).each do |function_name|
|
26
|
+
rule.function_names << function_name
|
27
|
+
end
|
28
|
+
rule.indent_string = "\t"
|
29
|
+
AnbtSql::Formatter.new(rule).format(sql.squeeze(" "))
|
30
|
+
end
|
31
|
+
end
|
data/lib/flog/version.rb
ADDED
data/rails-flog.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'flog/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rails-flog"
|
8
|
+
spec.version = Flog::VERSION
|
9
|
+
spec.authors = ["pinzolo"]
|
10
|
+
spec.email = ["pinzolo@gmail.com"]
|
11
|
+
spec.description = %q{This formats parameters and sql in rails log.}
|
12
|
+
spec.summary = %q{Rails log formatter for parameters and sql}
|
13
|
+
spec.homepage = "https://github.com/pinzolo/rails-flog"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "sqlite3"
|
24
|
+
spec.add_development_dependency "coveralls"
|
25
|
+
|
26
|
+
spec.add_dependency "rails", ">=3.2.0"
|
27
|
+
spec.add_dependency "anbt-sql-formatter"
|
28
|
+
spec.add_dependency "awesome_print"
|
29
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "coveralls"
|
3
|
+
require "simplecov"
|
4
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
5
|
+
SimpleCov.start do
|
6
|
+
add_filter '/test/'
|
7
|
+
add_filter '/bundle/'
|
8
|
+
end
|
9
|
+
|
10
|
+
Bundler.require
|
11
|
+
require "flog"
|
12
|
+
require "test/unit"
|
13
|
+
|
14
|
+
class TestLogger
|
15
|
+
attr_accessor :debugs, :infos, :errors
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@debugs = []
|
19
|
+
@infos = []
|
20
|
+
@errors = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def debug?
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
def info?
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
def debug(message)
|
32
|
+
@debugs += message.split("\n")
|
33
|
+
end
|
34
|
+
|
35
|
+
def info(message)
|
36
|
+
@infos += message.split("\n")
|
37
|
+
end
|
38
|
+
|
39
|
+
def error(message)
|
40
|
+
@errors += message.split("\n")
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "action_controller"
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
class TestController < ActionController::Base
|
6
|
+
def initialize(routes)
|
7
|
+
@routes = routes
|
8
|
+
end
|
9
|
+
|
10
|
+
def _routes
|
11
|
+
@routes
|
12
|
+
end
|
13
|
+
|
14
|
+
def show
|
15
|
+
render nothing: true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class ParamsFormattableTest < ActionController::TestCase
|
20
|
+
def setup
|
21
|
+
@old_logger = ActionController::Base.logger
|
22
|
+
ActiveSupport::LogSubscriber.colorize_logging = false
|
23
|
+
@routes = ActionDispatch::Routing::RouteSet.new
|
24
|
+
@routes.draw do
|
25
|
+
get "test/show", to: "test#show"
|
26
|
+
end
|
27
|
+
@controller = TestController.new(@routes)
|
28
|
+
super
|
29
|
+
ActionController::Base.logger = TestLogger.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def teardown
|
33
|
+
super
|
34
|
+
ActionController::Base.logger = @old_logger
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_parameters_log_is_formatted
|
38
|
+
get :show, foo: "foo_value", bar: "bar_value"
|
39
|
+
assert_logger do |logger|
|
40
|
+
logs = logger.infos.map { |log| log.gsub(/\e\[(\d+;)*\d+m/, "") }
|
41
|
+
assert_equal %( Parameters: ) , logs[1]
|
42
|
+
assert_equal %({) , logs[2]
|
43
|
+
assert_equal %( "foo" => "foo_value",), logs[3]
|
44
|
+
assert_equal %( "bar" => "bar_value") , logs[4]
|
45
|
+
assert_equal %(}) , logs[5]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_colorized_on_colorize_loggin_is_true
|
50
|
+
ActiveSupport::LogSubscriber.colorize_logging = true
|
51
|
+
get :show, foo: "foo_value", bar: "bar_value"
|
52
|
+
assert_logger do |logger|
|
53
|
+
assert /\e\[(\d+;)*\d+m/.match(logger.infos.join())
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_not_colorized_on_colorize_loggin_is_false
|
58
|
+
get :show, foo: "foo_value", bar: "bar_value"
|
59
|
+
assert_logger do |logger|
|
60
|
+
assert_nil /\e\[(\d+;)*\d+m/.match(logger.infos.join())
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
def assert_logger(&block)
|
66
|
+
if ActionController::Base.logger.errors.present?
|
67
|
+
fail ActionController::Base.logger.errors.first
|
68
|
+
else
|
69
|
+
block.call(ActionController::Base.logger)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "test_helper"
|
3
|
+
|
4
|
+
class TestClass
|
5
|
+
include PayloadValueShuntable
|
6
|
+
end
|
7
|
+
|
8
|
+
class PayloadValueShuntableTest < ActiveSupport::TestCase
|
9
|
+
def setup
|
10
|
+
@tester = TestClass.new
|
11
|
+
@payload = { foo: "foo_value", bar: "bar_value" }
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_shunt_payload_value
|
15
|
+
@tester.shunt_payload_value(@payload, :foo, "new_value") do
|
16
|
+
assert_equal "new_value", @payload[:foo]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_value_of_other_key_is_not_changed
|
21
|
+
@tester.shunt_payload_value(@payload, :foo, "new_value") do
|
22
|
+
assert_equal "bar_value", @payload[:bar]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_restoration
|
27
|
+
@tester.shunt_payload_value(@payload, :foo, "new_value") do
|
28
|
+
assert_equal "new_value", @payload[:foo]
|
29
|
+
end
|
30
|
+
assert_equal "foo_value", @payload[:foo]
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_ensure_restoration_on_error_raised_in_block
|
34
|
+
error_raised = false
|
35
|
+
begin
|
36
|
+
@tester.shunt_payload_value(@payload, :foo, "new_value") do
|
37
|
+
raise "error"
|
38
|
+
end
|
39
|
+
rescue => ex
|
40
|
+
error_raised = true
|
41
|
+
end
|
42
|
+
assert error_raised
|
43
|
+
assert_equal "foo_value", @payload[:foo]
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_without_block
|
47
|
+
@tester.shunt_payload_value(@payload, :foo, "new_value")
|
48
|
+
assert_equal "foo_value", @payload[:foo]
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_key_removed_when_give_not_exist_key
|
52
|
+
@tester.shunt_payload_value(@payload, :baz, "new_value") do
|
53
|
+
assert_equal "new_value", @payload[:baz]
|
54
|
+
end
|
55
|
+
assert_equal false, @payload.key?(:baz)
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "active_record"
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
6
|
+
|
7
|
+
ActiveRecord::Schema.define version: 0 do
|
8
|
+
create_table :books, force: true do |t|
|
9
|
+
t.string :name
|
10
|
+
t.string :category
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Book < ActiveRecord::Base; end
|
15
|
+
|
16
|
+
class SqlFormattableTest < ActiveSupport::TestCase
|
17
|
+
def setup
|
18
|
+
@old_logger = ActiveRecord::Base.logger
|
19
|
+
ActiveSupport::LogSubscriber.colorize_logging = false
|
20
|
+
ActiveRecord::Base.logger = TestLogger.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
ActiveRecord::Base.logger = @old_logger
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_sql_is_formatted
|
28
|
+
Book.where(category: "comics").to_a
|
29
|
+
assert_logger do |logger|
|
30
|
+
logs = logger.debugs.map { |log| log.gsub("\t", " ") }
|
31
|
+
assert_equal %{ SELECT} , logs[1]
|
32
|
+
assert_equal %{ "books" . *} , logs[2]
|
33
|
+
assert_equal %{ FROM} , logs[3]
|
34
|
+
assert_equal %{ "books"} , logs[4]
|
35
|
+
assert_equal %{ WHERE} , logs[5]
|
36
|
+
assert_equal %{ "books" . "category" = 'comics'}, logs[6]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_colorized_on_colorize_loggin_is_true
|
41
|
+
ActiveSupport::LogSubscriber.colorize_logging = true
|
42
|
+
Book.where(category: "comics").to_a
|
43
|
+
assert_logger do |logger|
|
44
|
+
assert /\e\[(\d+;)*\d+m/.match(logger.debugs.join())
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_not_colorized_on_colorize_loggin_is_false
|
49
|
+
Book.where(category: "comics").to_a
|
50
|
+
assert_logger do |logger|
|
51
|
+
assert_nil /\e\[(\d+;)*\d+m/.match(logger.debugs.join())
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def assert_logger(&block)
|
57
|
+
if ActiveRecord::Base.logger.errors.present?
|
58
|
+
fail ActiveRecord::Base.logger.errors.first
|
59
|
+
else
|
60
|
+
block.call(ActiveRecord::Base.logger)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-flog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- pinzolo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.2.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.2.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: anbt-sql-formatter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: awesome_print
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: This formats parameters and sql in rails log.
|
112
|
+
email:
|
113
|
+
- pinzolo@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .coveralls.yml
|
119
|
+
- .gitignore
|
120
|
+
- .travis.yml
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- gemfiles/activemodel_3_2_x.gemfile
|
126
|
+
- gemfiles/activemodel_4_0_x.gemfile
|
127
|
+
- lib/flog.rb
|
128
|
+
- lib/flog/params_formattable.rb
|
129
|
+
- lib/flog/payload_value_shuntable.rb
|
130
|
+
- lib/flog/sql_formattable.rb
|
131
|
+
- lib/flog/version.rb
|
132
|
+
- rails-flog.gemspec
|
133
|
+
- test/test_helper.rb
|
134
|
+
- test/unit/params_formattable_test.rb
|
135
|
+
- test/unit/payload_value_shuntable_test.rb
|
136
|
+
- test/unit/sql_formattable_test.rb
|
137
|
+
homepage: https://github.com/pinzolo/rails-flog
|
138
|
+
licenses:
|
139
|
+
- MIT
|
140
|
+
metadata: {}
|
141
|
+
post_install_message:
|
142
|
+
rdoc_options: []
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - '>='
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 2.0.3
|
158
|
+
signing_key:
|
159
|
+
specification_version: 4
|
160
|
+
summary: Rails log formatter for parameters and sql
|
161
|
+
test_files:
|
162
|
+
- test/test_helper.rb
|
163
|
+
- test/unit/params_formattable_test.rb
|
164
|
+
- test/unit/payload_value_shuntable_test.rb
|
165
|
+
- test/unit/sql_formattable_test.rb
|