ci_logger 0.6.0 → 0.8.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: a3ef69b1f08389623edc46eadeecb5caab6cd9cc5cf993b6eddf8f964c3b8908
4
+ data.tar.gz: 5aa92e9108400d33f65c075996498030cd69922ec8d9e568ae8b2cb888954d54
5
5
  SHA512:
6
- metadata.gz: 374b4100e406ac38d424dcebcbbe8c8d5759ca224a71a5025cade5de9d59b7e62f0d288547f3f2264f2c286d1a617c17e9f34de9ddb508d3fb1532b4fbe63e08
7
- data.tar.gz: 741390996e587d384281854f135b5a0c5532cd633e66138f2ae578bb407d56985066d06f8766648159e587c722489452e5d2c1dff85d54f2b76f5d8ec2bb4acc
6
+ metadata.gz: b792b58199a032f4cf4e1404f40e5625e5f34b7064b5a32e57299a4a6e285cd6116fce0d84b8a0439a2800052d5f0a931e682c4799e83771bd79ca383a3738a0
7
+ data.tar.gz: e5215e8fa3f9c60928f8526858f0ad2f8f462954a9b39377193aec190cf60ee241ef157560f090be7e7c670d67cfac6dfde4f94e10f26de5d4bd042b5bb182fa
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,46 +1,23 @@
1
+ require "ci_logger/registry"
2
+
1
3
  module CiLogger
2
- class Logger < ::Logger
4
+ class Logger
3
5
  def initialize(original)
4
6
  @original = original
5
- @original_level = @original.level
6
- @original.level = :debug
7
- self.level = :debug
7
+ Registry.register(self)
8
8
  end
9
9
 
10
10
  def sync
11
11
  temporary_log.each do |l|
12
- if @level <= l[:severity]
13
- @original.add(l[:severity], l[:message], l[:progname])
14
- end
12
+ @original.add(l[:severity], l[:message], l[:progname])
15
13
  end
16
14
  temporary_log.clear
17
15
  end
18
16
 
19
- def sync_with_original_level
20
- @original.level = @original_level
21
- sync
22
- ensure
23
- @original.level = :debug
24
- end
25
-
26
17
  def clear
27
18
  temporary_log.clear
28
19
  end
29
20
 
30
- def formatter
31
- @original.formatter
32
- end
33
-
34
- def formatter=(f)
35
- @original.formatter = f
36
- end
37
-
38
- private
39
-
40
- def temporary_log
41
- @temporary_log ||= []
42
- end
43
-
44
21
  def add(severity, message = nil, progname = nil)
45
22
  if progname.nil?
46
23
  progname = @progname
@@ -56,12 +33,42 @@ module CiLogger
56
33
  temporary_log << { severity: severity, message: message, progname: progname }
57
34
  end
58
35
 
59
- def method_missing(symbol, *args, &block)
60
- @original.send(symbol, *args, &block)
36
+ def debug(progname = nil, &block)
37
+ add(::Logger::DEBUG, nil, progname, &block)
38
+ end
39
+
40
+ def info(progname = nil, &block)
41
+ add(::Logger::INFO, nil, progname, &block)
42
+ end
43
+
44
+ def warn(progname = nil, &block)
45
+ add(::Logger::WARN, nil, progname, &block)
46
+ end
47
+
48
+ def error(progname = nil, &block)
49
+ add(::Logger::ERROR, nil, progname, &block)
50
+ end
51
+
52
+ def fatal(progname = nil, &block)
53
+ add(::Logger::FATAL, nil, progname, &block)
54
+ end
55
+
56
+ def unknown(progname = nil, &block)
57
+ add(::Logger::UNKNOWN, nil, progname, &block)
58
+ end
59
+
60
+ private
61
+
62
+ def temporary_log
63
+ @temporary_log ||= []
64
+ end
65
+
66
+ def method_missing(...)
67
+ @original.send(...)
61
68
  end
62
69
 
63
- def respond_to_missing?(symbol, include_all)
64
- @original.respond_to?(symbol, include_all)
70
+ def respond_to_missing?(...)
71
+ @original.respond_to?(...)
65
72
  end
66
73
  end
67
74
  end
@@ -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.8.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.8.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-11-15 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