ci_logger 0.1.0

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
+ SHA256:
3
+ metadata.gz: 3360b4b4e26f728a5b149f75da20bc3d59bdc1a854cd636d4c27c1d47472a59d
4
+ data.tar.gz: 4c9e073889772abd247c543b349f8b882f0c300b960ef4c79e27e2289c7f14a2
5
+ SHA512:
6
+ metadata.gz: 72beb64465367ab6fd393ed95482ddd0ee0c13555b8af0e054eda9cb38a22626834ac98cd16f7c9ad74ad5ace71e937a1908a0e852eb4842bcf7caa20ea04c9e
7
+ data.tar.gz: 3347289824b412d2a34997f703d8ace941b4c1fb3cc28673bcea8cd5d1bf5727199cf8601c7db778440daf6d8cc5d2b7395daae67ee14f16faa576fa5b7798dd
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2021 willnet
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # CiLogger
2
+
3
+ Faster Logger for CI
4
+
5
+ ## prerequisite
6
+
7
+ - rspec-rails
8
+ - rails(>= 5.2)
9
+
10
+ If you want minitest integration, send Pull Request!
11
+
12
+ ## Usage
13
+
14
+ As time pass, CI time increase gradually. Log output takes some times in CI, So someone may want to set :info or :error to loglevel. But we want debug log when CI fails to inspect the root cause. CiLogger output debug log only when CI fails. So we are able to logs and get faster CI.
15
+
16
+ ## Installation
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'ci_logger', group: :test
21
+ ```
22
+
23
+ And then execute:
24
+ ```bash
25
+ $ bundle
26
+ ```
27
+
28
+ Or install it yourself as:
29
+ ```bash
30
+ $ gem install ci_logger
31
+ ```
32
+
33
+ Add this line to your config/environments/test.rb
34
+
35
+ ```ruby
36
+ config.ci_logger.enabled = ENV['CI']
37
+ ```
38
+
39
+ You can replace `ENV['CI']` with what you like.
40
+
41
+ ## Contributing
42
+ Contribution directions go here.
43
+
44
+ ## License
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ require "rake/testtask"
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = false
11
+ end
12
+
13
+ task default: :test
@@ -0,0 +1,30 @@
1
+ module CiLogger
2
+ class Logger < ::Logger
3
+ def initialize(original)
4
+ @original = original
5
+ @original.level = :debug
6
+ self.level = :debug
7
+ end
8
+
9
+ def clear
10
+ temporary_log.clear
11
+ end
12
+
13
+ def temporary_log
14
+ @temporary_log ||= []
15
+ end
16
+
17
+ def add(severity, message = nil, progname = nil)
18
+ temporary_log << { severity: severity, message: message, progname: progname }
19
+ end
20
+
21
+ def sync
22
+ temporary_log.each do |l|
23
+ if @level <= l[:severity]
24
+ @original.add(l[:severity], l[:message], l[:progname])
25
+ end
26
+ end
27
+ temporary_log.clear
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ module CiLogger
2
+ class Railtie < ::Rails::Railtie
3
+ config.ci_logger = ActiveSupport::OrderedOptions.new
4
+ config.ci_logger.enabled = false
5
+
6
+ config.before_initialize do
7
+ if config.ci_logger.enabled
8
+ Rails.logger = CiLogger::Logger.new(Rails.logger)
9
+
10
+ RSpec.configure do |config|
11
+ config.add_formatter 'progress'
12
+ config.add_formatter ::CiLogger::Formatter
13
+ config.before do |example|
14
+ Rails.logger.debug("start example at #{example.location}")
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module CiLogger
2
+ VERSION = '0.1.0'
3
+ end
data/lib/ci_logger.rb ADDED
@@ -0,0 +1,36 @@
1
+ require "ci_logger/version"
2
+ require "ci_logger/railtie"
3
+ require "ci_logger/logger"
4
+
5
+ module CiLogger
6
+ begin
7
+ require "rspec/rails"
8
+
9
+ class Formatter
10
+ RSpec::Core::Formatters.register self, :example_passed, :example_pending, :example_failed
11
+
12
+ def initialize(_out)
13
+ @out = _out
14
+ end
15
+
16
+ def example_failed(notification)
17
+ if Rails.application.config.ci_logger.enabled
18
+ example = notification.example
19
+ Rails.logger.debug("finish example at #{example.location}")
20
+ Rails.logger.sync
21
+ else
22
+ Rails.logger.clear
23
+ end
24
+ end
25
+
26
+ def example_passed(_notification)
27
+ Rails.logger.clear
28
+ end
29
+
30
+ def example_pending(_notification)
31
+ Rails.logger.clear
32
+ end
33
+ end
34
+ rescue LoadError
35
+ end
36
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :ci_logger do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ci_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - willnet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-23 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: 5.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Faster logger for CI
42
+ email:
43
+ - netwillnet@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - lib/ci_logger.rb
52
+ - lib/ci_logger/logger.rb
53
+ - lib/ci_logger/railtie.rb
54
+ - lib/ci_logger/version.rb
55
+ - lib/tasks/ci_logger_tasks.rake
56
+ homepage: https://github.com/willnet/ci_logger
57
+ licenses:
58
+ - MIT
59
+ metadata:
60
+ homepage_uri: https://github.com/willnet/ci_logger
61
+ source_code_uri: https://github.com/willnet/ci_logger
62
+ changelog_uri: https://github.com/willnet/ci_logger
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.2.22
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Faster logger for CI
82
+ test_files: []