ci_logger 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ea3c804f1e3d3355f06ef8a71931c4c87f27e28b9e851505454ce0e3889e1b3
4
- data.tar.gz: 9243562646418cd0f1849c6d1e65c93832380641640bd92b0aa4ec3a4aed7cad
3
+ metadata.gz: 51c9f02d787a2ea528d373395735b2a3f442c410b371b3a678cff837245056e2
4
+ data.tar.gz: b64fc8ea5f7f8590cf102b6ceb24bf47b113014061b526753ed12a22c8eec166
5
5
  SHA512:
6
- metadata.gz: 374b4100e406ac38d424dcebcbbe8c8d5759ca224a71a5025cade5de9d59b7e62f0d288547f3f2264f2c286d1a617c17e9f34de9ddb508d3fb1532b4fbe63e08
7
- data.tar.gz: 741390996e587d384281854f135b5a0c5532cd633e66138f2ae578bb407d56985066d06f8766648159e587c722489452e5d2c1dff85d54f2b76f5d8ec2bb4acc
6
+ metadata.gz: acfa40bed44dc82d44e311cf5a8124c32545176d8361e57e3fa82ae0b6a3bcc20bb3a201a4a6b84338eb6e4fc27d447e8ca8efaad14fe23343cbe24b5e08cbe8
7
+ data.tar.gz: 0eb2d0c042f3e926ee34368e9681200f676f30f54860bad8ff636b44c952e3cd94ec86084bbf77966d3ec529e815cb3995eebb71070b6dd10fb7836866f3a6bf
data/README.md CHANGED
@@ -35,6 +35,15 @@ config.ci_logger.enabled = ENV['CI']
35
35
 
36
36
  You can replace `ENV['CI']` with what you like.
37
37
 
38
+ ## Replace loggers besides rails logger
39
+
40
+ CiLogger replaces Rails.logger by default, but other loggers can be replaced.
41
+
42
+ ```ruby
43
+ your_logger = CiLogger.new(your_logger)
44
+ your_logger.debug('debug!') # This is only output when the test fails
45
+ ```
46
+
38
47
  ## Contributing
39
48
  Contribution directions go here.
40
49
 
@@ -1,3 +1,5 @@
1
+ require "ci_logger/registry"
2
+
1
3
  module CiLogger
2
4
  class Logger < ::Logger
3
5
  def initialize(original)
@@ -5,6 +7,7 @@ module CiLogger
5
7
  @original_level = @original.level
6
8
  @original.level = :debug
7
9
  self.level = :debug
10
+ Registry.register(self)
8
11
  end
9
12
 
10
13
  def sync
@@ -3,12 +3,12 @@ module CiLogger
3
3
  module Integration
4
4
  def before_teardown
5
5
  super
6
- if !Rails.application.config.ci_logger.enabled
7
- Rails.logger.sync
6
+ if CiLogger.disabled?
7
+ Registry.sync
8
8
  elsif passed? || skipped?
9
- Rails.logger.clear
9
+ Registry.clear
10
10
  else
11
- Rails.logger.sync
11
+ Registry.sync
12
12
  end
13
13
  end
14
14
  end
@@ -4,7 +4,7 @@ module CiLogger
4
4
  config.ci_logger.enabled = false
5
5
 
6
6
  config.before_initialize do
7
- if Rails.application.config.ci_logger.enabled
7
+ if CiLogger.enabled?
8
8
  Rails.logger = CiLogger::Logger.new(Rails.logger)
9
9
  begin
10
10
  require "rspec/core"
@@ -0,0 +1,22 @@
1
+ module CiLogger
2
+ module Registry
3
+ class << self
4
+ def register(logger)
5
+ @loggers ||= []
6
+ @loggers << logger
7
+ end
8
+
9
+ def sync
10
+ @loggers.each(&:sync)
11
+ end
12
+
13
+ def clear
14
+ @loggers.each(&:clear)
15
+ end
16
+
17
+ def debug(...)
18
+ @loggers.each { _1.debug(...) }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -4,19 +4,19 @@ RSpec.configure do |config|
4
4
  config.include CiLogger::Rspec::ExampleGroupMethods
5
5
 
6
6
  config.prepend_before do |example|
7
- next unless Rails.application.config.ci_logger.enabled
7
+ next if CiLogger.disabled?
8
8
 
9
- Rails.logger.debug("start example at #{example.location}")
9
+ CiLogger::Registry.debug("start example at #{example.location}")
10
10
  end
11
11
 
12
12
  config.append_after do |example|
13
- if !Rails.application.config.ci_logger.enabled
14
- Rails.logger.sync
13
+ if CiLogger.disabled?
14
+ CiLogger::Registry.sync
15
15
  elsif passed?
16
- Rails.logger.clear
16
+ CiLogger::Registry.clear
17
17
  else
18
- Rails.logger.debug("finish example at #{example.location}")
19
- Rails.logger.sync
18
+ CiLogger::Registry.debug("finish example at #{example.location}")
19
+ CiLogger::Registry.sync
20
20
  end
21
21
  end
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module CiLogger
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  end
data/lib/ci_logger.rb CHANGED
@@ -3,4 +3,17 @@ require "ci_logger/railtie"
3
3
  require "ci_logger/logger"
4
4
 
5
5
  module CiLogger
6
+ class << self
7
+ def new(original)
8
+ Logger.new(original)
9
+ end
10
+
11
+ def enabled?
12
+ Rails.application.config.ci_logger.enabled
13
+ end
14
+
15
+ def disabled?
16
+ !enabled?
17
+ end
18
+ end
6
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ci_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - willnet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-15 00:00:00.000000000 Z
11
+ date: 2023-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -52,6 +52,7 @@ files:
52
52
  - lib/ci_logger/logger.rb
53
53
  - lib/ci_logger/minitest/integration.rb
54
54
  - lib/ci_logger/railtie.rb
55
+ - lib/ci_logger/registry.rb
55
56
  - lib/ci_logger/rspec/example_group_methods.rb
56
57
  - lib/ci_logger/rspec/integration.rb
57
58
  - lib/ci_logger/version.rb