paul_bunyan 1.5.2 → 1.5.3

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
- SHA1:
3
- metadata.gz: 171388d288887542610c069c558db27316b5126e
4
- data.tar.gz: fe2ec569d2228aa11a55e2b16bdbcaacd5075a92
2
+ SHA256:
3
+ metadata.gz: 6cd239b74337270ec4552ab5b968097fb992fc10f16865db5636a72b470e8d01
4
+ data.tar.gz: '09a9523fcc3b38208a572ffe57baebfa28c085c709c3ac0adf94b4db34982035'
5
5
  SHA512:
6
- metadata.gz: 28d191b3a06b5d193e1bcf530a8e60ae0de981909695009d7610d256db62fb8ad459c1ec50b6efe43aa7af9c543cf34d516a52f91fc589a7f62801832d46f146
7
- data.tar.gz: 960b65912617acd94f0eec1a67020586a2eb04243f770523e5861f24c1fee4e080c296058e76308e8e8fa0adaee4234ff8d023cc604cbd0dc6902630cdbb38fa
6
+ metadata.gz: 98d74e92f6f9b2c575ab9511b8070724aa181e1a7f8c60fa72f004db79eb301defdfdce8b185bb21ff034204383a7aeb190e7c748cba3b5e2722691c78a7391d
7
+ data.tar.gz: eb3cc2f0857fd064339635230a56246adbab2da6a88a3c95e72696fe3be4db246462e083aaa6d40ed96c4368ea4c0d7c686a46acbe0f2d9551a3040791402f3e
@@ -1,23 +1,31 @@
1
1
  module PaulBunyan
2
2
  module MetadataLogging
3
3
  def clear_metadata!
4
- formatter.clear_metadata!
4
+ formatter.clear_metadata! if formatter.respond_to?(:clear_metadata!)
5
5
  end
6
6
 
7
7
  def with_metadata(metadata)
8
- formatter.with_metadata(metadata) { yield self }
8
+ if formatter.respond_to?(:with_metadata)
9
+ formatter.with_metadata(metadata) { yield self }
10
+ else
11
+ yield self
12
+ end
9
13
  end
10
14
 
11
15
  def add_metadata(metadata)
12
- formatter.add_metadata(metadata)
16
+ formatter.add_metadata(metadata) if formatter.respond_to?(:add_metadata)
13
17
  end
14
18
 
15
19
  def remove_metadata(metadata)
16
- formatter.remove_metadata(metadata)
20
+ formatter.remove_metadata(metadata) if formatter.respond_to?(:remove_metadata)
17
21
  end
18
22
 
19
23
  def current_metadata
20
- formatter.current_metadata
24
+ if formatter.respond_to?(:current_metadata)
25
+ return formatter.current_metadata
26
+ else
27
+ return {}
28
+ end
21
29
  end
22
30
 
23
31
  def flush
@@ -17,6 +17,16 @@ module PaulBunyan
17
17
  Rails.env.development? || Rails.env.test?
18
18
  end
19
19
 
20
+ def self.rake_task?
21
+ File.basename($0) == 'rake'
22
+ end
23
+
24
+ def self.migrating?
25
+ rake_task? && ARGV.include?('db:migrate')
26
+ end
27
+
28
+ delegate :rake_task?, :migrating?, to: :class
29
+
20
30
  # Set up the config and some defaults
21
31
  config.logging = ActiveSupport::OrderedOptions.new
22
32
  config.logging.override_location = !Rails.env.test?
@@ -27,18 +37,20 @@ module PaulBunyan
27
37
  initializer 'initalize_logger.logging', group: :all, before: :initialize_logger do |app|
28
38
  logging_config = config.logging
29
39
 
30
- new_logger = PaulBunyan.add_logger(ActiveSupport::Logger.new(log_target(app.config)))
31
- new_logger.level = PaulBunyan::Level.coerce_level(ENV['LOG_LEVEL'] || ::Rails.application.config.log_level || 'INFO')
32
- new_logger.formatter = logging_config.formatter
33
- new_logger.extend(ActiveSupport::TaggedLogging) if logging_config.formatter.respond_to?(:tagged)
34
- new_logger.extend(PaulBunyan::MetadataLogging) if logging_config.formatter.respond_to?(:with_metadata)
40
+ unless migrating?
41
+ new_logger = PaulBunyan.add_logger(ActiveSupport::Logger.new(log_target(app.config)))
42
+ new_logger.level = PaulBunyan::Level.coerce_level(ENV['LOG_LEVEL'] || ::Rails.application.config.log_level || 'INFO')
43
+ new_logger.formatter = logging_config.formatter
44
+ new_logger.extend(ActiveSupport::TaggedLogging) if logging_config.formatter.respond_to?(:tagged)
45
+ new_logger.extend(PaulBunyan::MetadataLogging) if logging_config.formatter.respond_to?(:with_metadata)
35
46
 
36
- if logging_config.handle_request_logging
37
- unsubscribe_default_log_subscribers
38
- LogSubscriber.subscribe_to_events
39
- end
47
+ if logging_config.handle_request_logging
48
+ unsubscribe_default_log_subscribers
49
+ LogSubscriber.subscribe_to_events
50
+ end
40
51
 
41
- Rails.logger = PaulBunyan.logger
52
+ Rails.logger = PaulBunyan.logger
53
+ end
42
54
  end
43
55
 
44
56
  console do
@@ -5,7 +5,7 @@ end
5
5
 
6
6
  module PaulBunyan
7
7
  class TextFormatter < Logger::Formatter
8
- include ActiveSupport::TaggedLogging::Formatter if defined?(ActiveSupport::TaggedLogging)
8
+ include ActiveSupport::TaggedLogging::Formatter if defined?(ActiveSupport::TaggedLogging::Formatter)
9
9
 
10
10
  def initialize(include_metadata: true)
11
11
  @include_metadata = include_metadata
@@ -1,3 +1,3 @@
1
1
  module PaulBunyan
2
- VERSION = '1.5.2'
2
+ VERSION = '1.5.3'
3
3
  end
@@ -1,62 +1,108 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe PaulBunyan::MetadataLogging do
4
- subject { Object.new }
5
- let(:formatter) { double('formatter') }
4
+ context "with a formatter that supports metadata" do
5
+ subject { Object.new }
6
+ let(:formatter) { double('formatter') }
6
7
 
7
- before do
8
- subject.extend(PaulBunyan::MetadataLogging)
9
- allow(subject).to receive(:formatter).and_return(formatter)
10
- end
8
+ before do
9
+ subject.extend(PaulBunyan::MetadataLogging)
10
+ allow(subject).to receive(:formatter).and_return(formatter)
11
+ end
11
12
 
12
- it 'must delegate clear_metadata! to the formatter' do
13
- expect(formatter).to receive(:clear_metadata!)
14
- subject.clear_metadata!
15
- end
13
+ it 'must delegate clear_metadata! to the formatter' do
14
+ expect(formatter).to receive(:clear_metadata!)
15
+ subject.clear_metadata!
16
+ end
16
17
 
17
- it 'must delegate with_metadata to the formatter' do
18
- expect(formatter).to receive(:with_metadata).with(foo: 'bar').and_yield
19
- subject.with_metadata(foo: 'bar') do |logger|
20
- expect(subject).to eq logger
18
+ it 'must delegate with_metadata to the formatter' do
19
+ expect(formatter).to receive(:with_metadata).with(foo: 'bar').and_yield
20
+ subject.with_metadata(foo: 'bar') do |logger|
21
+ expect(subject).to eq logger
22
+ end
21
23
  end
22
- end
23
24
 
24
- it 'must delegate add_metadata to the formatter' do
25
- expect(formatter).to receive(:add_metadata).with(foo: 'bar')
26
- subject.add_metadata(foo: 'bar')
27
- end
25
+ it 'must delegate add_metadata to the formatter' do
26
+ expect(formatter).to receive(:add_metadata).with(foo: 'bar')
27
+ subject.add_metadata(foo: 'bar')
28
+ end
28
29
 
29
- it 'must delegate current_metadata to the formatter' do
30
- expect(formatter).to receive(:current_metadata).and_return({})
31
- subject.current_metadata
32
- end
30
+ it 'must delegate current_metadata to the formatter' do
31
+ expect(formatter).to receive(:current_metadata).and_return({})
32
+ subject.current_metadata
33
+ end
34
+
35
+ it 'must delegate remove_metadata to the formatter' do
36
+ expect(formatter).to receive(:remove_metadata).with(foo: 'bar')
37
+ subject.remove_metadata(foo: 'bar')
38
+ end
39
+
40
+ context '#flush' do
41
+ it 'clears metadata on the formatter' do
42
+ expect(formatter).to receive(:clear_metadata!)
43
+ subject.flush
44
+ end
45
+
46
+ it 'sends flush to a parent' do
47
+ klass = Class.new
48
+ klass.class_eval do
49
+ def flush
50
+ flush_behavior()
51
+ end
52
+ end
53
+
54
+ metadata_logger = klass.new
55
+ metadata_logger.extend(PaulBunyan::MetadataLogging)
56
+ allow(metadata_logger).to receive(:formatter).and_return(formatter)
57
+ allow(formatter).to receive(:clear_metadata!)
33
58
 
34
- it 'must delegate remove_metadata to the formatter' do
35
- expect(formatter).to receive(:remove_metadata).with(foo: 'bar')
36
- subject.remove_metadata(foo: 'bar')
59
+ expect(metadata_logger).to receive(:flush_behavior)
60
+ metadata_logger.flush
61
+ end
62
+ end
37
63
  end
38
64
 
39
- context '#flush' do
40
- it 'clears metadata on the formatter' do
41
- expect(formatter).to receive(:clear_metadata!)
42
- subject.flush
65
+ context "with a formatter that does not support metadata" do
66
+ subject { Object.new }
67
+ let(:formatter) { PaulBunyan::TextFormatter.new }
68
+
69
+ before do
70
+ subject.extend(PaulBunyan::MetadataLogging)
71
+ allow(subject).to receive(:formatter).and_return(formatter)
43
72
  end
44
73
 
45
- it 'sends flush to a parent' do
46
- klass = Class.new
47
- klass.class_eval do
48
- def flush
49
- flush_behavior()
50
- end
74
+ it 'must not call clear_metadata! on the formatter' do
75
+ expect(formatter).to_not respond_to(:clear_metadata!)
76
+ subject.clear_metadata!
77
+ end
78
+
79
+ it 'must delegate with_metadata to the formatter' do
80
+ expect(formatter).to_not respond_to(:with_metadata)
81
+ subject.with_metadata(foo: 'bar') do |logger|
82
+ expect(subject).to eq logger
51
83
  end
84
+ end
85
+
86
+ it 'must delegate add_metadata to the formatter' do
87
+ expect(formatter).to_not respond_to(:add_metadata)
88
+ subject.add_metadata(foo: 'bar')
89
+ end
52
90
 
53
- metadata_logger = klass.new
54
- metadata_logger.extend(PaulBunyan::MetadataLogging)
55
- allow(metadata_logger).to receive(:formatter).and_return(formatter)
56
- allow(formatter).to receive(:clear_metadata!)
91
+ it 'must delegate current_metadata to the formatter' do
92
+ expect(formatter).to_not respond_to(:current_metadata)
93
+ subject.current_metadata
94
+ end
95
+
96
+ it 'must delegate remove_metadata to the formatter' do
97
+ expect(formatter).to_not respond_to(:remove_metadata)
98
+ subject.remove_metadata(foo: 'bar')
99
+ end
57
100
 
58
- expect(metadata_logger).to receive(:flush_behavior)
59
- metadata_logger.flush
101
+ context '#flush' do
102
+ it 'clears metadata on the formatter' do
103
+ expect(formatter).to_not respond_to(:clear_metadata!)
104
+ subject.flush
105
+ end
60
106
  end
61
107
  end
62
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paul_bunyan
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Duane Johnson
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-02-14 00:00:00.000000000 Z
14
+ date: 2018-11-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: request_store
@@ -243,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
243
  version: '0'
244
244
  requirements: []
245
245
  rubyforge_project:
246
- rubygems_version: 2.6.13
246
+ rubygems_version: 2.7.6
247
247
  signing_key:
248
248
  specification_version: 4
249
249
  summary: Logging for all the things