truncate_logs 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b8f61721dcf81ef3e4ad0c3d9093e8800a65da17
4
+ data.tar.gz: d2bb42986f128047168b03540810403c52778f6b
5
+ SHA512:
6
+ metadata.gz: 3d829e8e72909010d491cf669a5de1bf1c980fb4ccfdb42aab8ddf1eb85d16069694df222d3eb517d6bdeca91e7ae0867dda7f5317e0c08e26e5f623fae7b68b
7
+ data.tar.gz: 86e2712588108344dc4b7e84cd0f0f6bfbafe668f648a8136705b1b916d71c1189b16b6b82f14dc56938537997ad130227ad91fd57fbd0255be5b0554753e617
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,148 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.2
3
+ # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
4
+ # to ignore them, so only the ones explicitly set in this file are enabled.
5
+ DisabledByDefault: true
6
+ Exclude:
7
+ - 'Rakefile'
8
+ - 'Gemfile'
9
+ - '*.gemspec'
10
+
11
+ # Prefer &&/|| over and/or.
12
+ Style/AndOr:
13
+ Enabled: true
14
+
15
+ # Do not use braces for hash literals when they are the last argument of a
16
+ # method call.
17
+ Style/BracesAroundHashParameters:
18
+ Enabled: true
19
+
20
+ # Align `when` with `case`.
21
+ Layout/CaseIndentation:
22
+ Enabled: true
23
+
24
+ # Align comments with method definitions.
25
+ Layout/CommentIndentation:
26
+ Enabled: true
27
+
28
+ Layout/EmptyLineAfterMagicComment:
29
+ Enabled: true
30
+
31
+ # No extra empty lines.
32
+ Layout/EmptyLines:
33
+ Enabled: true
34
+
35
+ # In a regular class definition, no empty lines around the body.
36
+ Layout/EmptyLinesAroundClassBody:
37
+ Enabled: true
38
+
39
+ # In a regular method definition, no empty lines around the body.
40
+ Layout/EmptyLinesAroundMethodBody:
41
+ Enabled: true
42
+
43
+ # In a regular module definition, no empty lines around the body.
44
+ Layout/EmptyLinesAroundModuleBody:
45
+ Enabled: true
46
+
47
+ Layout/FirstParameterIndentation:
48
+ Enabled: true
49
+
50
+ # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
51
+ Style/HashSyntax:
52
+ Enabled: true
53
+
54
+ # Method definitions after `private` or `protected` isolated calls need one
55
+ # extra level of indentation.
56
+ Layout/IndentationConsistency:
57
+ Enabled: true
58
+ EnforcedStyle: rails
59
+
60
+ # Two spaces, no tabs (for indentation).
61
+ Layout/IndentationWidth:
62
+ Enabled: true
63
+
64
+ Layout/SpaceAfterColon:
65
+ Enabled: true
66
+
67
+ Layout/SpaceAfterComma:
68
+ Enabled: true
69
+
70
+ Layout/SpaceAroundEqualsInParameterDefault:
71
+ Enabled: true
72
+
73
+ Layout/SpaceAroundKeyword:
74
+ Enabled: true
75
+
76
+ Layout/SpaceAroundOperators:
77
+ Enabled: true
78
+
79
+ Layout/SpaceBeforeFirstArg:
80
+ Enabled: true
81
+
82
+ # Defining a method with parameters needs parentheses.
83
+ Style/MethodDefParentheses:
84
+ Enabled: true
85
+
86
+ Style/FrozenStringLiteralComment:
87
+ Enabled: true
88
+ EnforcedStyle: always
89
+ Include:
90
+ - 'activesupport/**/*'
91
+ - 'activemodel/**/*'
92
+ - 'actioncable/**/*'
93
+ - 'activejob/**/*'
94
+ - 'activerecord/**/*'
95
+ - 'actionmailer/**/*'
96
+ - 'actionview/**/*'
97
+ - 'actionpack/**/*'
98
+ Exclude:
99
+ - 'actionview/test/**/*.builder'
100
+ - 'actionview/test/**/*.ruby'
101
+ - 'actionpack/test/**/*.builder'
102
+ - 'actionpack/test/**/*.ruby'
103
+
104
+ # Use `foo {}` not `foo{}`.
105
+ Layout/SpaceBeforeBlockBraces:
106
+ Enabled: true
107
+
108
+ # Use `foo { bar }` not `foo {bar}`.
109
+ Layout/SpaceInsideBlockBraces:
110
+ Enabled: true
111
+
112
+ # Use `{ a: 1 }` not `{a:1}`.
113
+ Layout/SpaceInsideHashLiteralBraces:
114
+ Enabled: true
115
+
116
+ Layout/SpaceInsideParens:
117
+ Enabled: true
118
+
119
+ # Check quotes usage according to lint rule below.
120
+ Style/StringLiterals:
121
+ Enabled: true
122
+ EnforcedStyle: double_quotes
123
+
124
+ # Detect hard tabs, no hard tabs.
125
+ Layout/Tab:
126
+ Enabled: true
127
+
128
+ # Blank lines should not have any spaces.
129
+ Layout/TrailingBlankLines:
130
+ Enabled: true
131
+
132
+ # No trailing whitespace.
133
+ Layout/TrailingWhitespace:
134
+ Enabled: true
135
+
136
+ # Use quotes for string literals when they are enough.
137
+ Style/UnneededPercentQ:
138
+ Enabled: true
139
+
140
+ # Align `end` with the matching keyword or starting expression except for
141
+ # assignments, where it should be aligned with the LHS.
142
+ Lint/EndAlignment:
143
+ Enabled: true
144
+ EnforcedStyleAlignWith: variable
145
+
146
+ # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
147
+ Lint/RequireParentheses:
148
+ Enabled: true
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in truncate_logs.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 yalab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # TruncateLogs
2
+
3
+ This gem provides too large rails logs truncated.
4
+
5
+ like that
6
+
7
+ ```
8
+ Fixture Insert (20.0ms) INSERT INTO "photos" ("name", "content", "created_at", "updated_at") VALUES ('avatar', '[TRUNCATE 368 KB]', '2017-08-29 07:49:17.416578', '2017-08-29 07:49:17.416578')
9
+ ```
10
+
11
+ ```
12
+ Processing by PhotosController#create as HTML
13
+ Parameters: {"photo"=>{"content"=>"[TRUNCATE 1 MB]"}}
14
+ Completed 200 OK in 0ms
15
+ ```
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ group :development, :test do
23
+ gem 'truncate_logs'
24
+ end
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle install
30
+
31
+ ## Usage
32
+
33
+ You should only install.
34
+
35
+ ## Development
36
+
37
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+
39
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yalab/truncate_logs.
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "truncate_logs"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ require "active_support/concern"
2
+ require "action_dispatch"
3
+
4
+ module ActionDispatch
5
+ module Http
6
+ module TruncateParameters
7
+ def filtered_parameters
8
+ params_truncate super
9
+ end
10
+
11
+ def params_truncate(original_params)
12
+ truncated_params = original_params.class.new
13
+ original_params.each do |k, v|
14
+ truncated_params[k] = if v.is_a?(Hash)
15
+ params_truncate(v)
16
+ else
17
+ truncate(v)
18
+ end
19
+ end
20
+ truncated_params
21
+ end
22
+
23
+ def truncate(value)
24
+ bytesize = value.bytesize
25
+ if bytesize >= 1.kilobyte
26
+ "[TRUNCATE #{bytesize.to_s(:human_size)}]"
27
+ else
28
+ value
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ ActionDispatch::Request.include ActionDispatch::Http::TruncateParameters
@@ -0,0 +1,13 @@
1
+ require 'active_record'
2
+ module TruncateLogs
3
+ module ActiveRecord
4
+ def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil)
5
+ sql = sql.gsub(/[^']{1024,}/) do |match|
6
+ "[TRUNCATE #{match.bytesize.to_s(:human_size)}]"
7
+ end
8
+ super
9
+ end
10
+ end
11
+ end
12
+
13
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:prepend, TruncateLogs::ActiveRecord)
@@ -0,0 +1,7 @@
1
+ require "truncate_logs/version"
2
+ require "action_dispatch/http/truncate_parameters"
3
+ require "active_record/truncate_logs"
4
+
5
+ module TruncateLogs
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,3 @@
1
+ module TruncateLogs
2
+ VERSION = "0.8.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "truncate_logs/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "truncate_logs"
8
+ spec.version = TruncateLogs::VERSION
9
+ spec.authors = ["yalab"]
10
+ spec.email = ["rudeboyjet@gmail.com"]
11
+
12
+ spec.summary = %q{Truncate logs for too large params or fixtures.}
13
+ spec.description = %q{If you use binary data post or so. Your log file is soon too large. This gem provides truncate too large params or fixutre loggings.}
14
+ spec.homepage = "https://github.com/yalab/truncate_logs"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.15"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+ spec.add_dependency "actionpack", "~>5.0"
28
+ spec.add_dependency "activesupport", "~>5.0"
29
+ spec.add_development_dependency "activerecord", "~> 5.0"
30
+ spec.add_development_dependency "sqlite3"
31
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: truncate_logs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0
5
+ platform: ruby
6
+ authors:
7
+ - yalab
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-29 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: actionpack
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activerecord
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: If you use binary data post or so. Your log file is soon too large. This
112
+ gem provides truncate too large params or fixutre loggings.
113
+ email:
114
+ - rudeboyjet@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rubocop.yml"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/action_dispatch/http/truncate_parameters.rb
129
+ - lib/active_record/truncate_logs.rb
130
+ - lib/truncate_logs.rb
131
+ - lib/truncate_logs/version.rb
132
+ - truncate_logs.gemspec
133
+ homepage: https://github.com/yalab/truncate_logs
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.6.11
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Truncate logs for too large params or fixtures.
157
+ test_files: []