loglevel 0.2.1 → 0.2.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
2
  SHA1:
3
- metadata.gz: 1bd8c2f39f120e520842eba218003ea8b70ae4e8
4
- data.tar.gz: 7e36d867091c81a083582f5ccf0c61681406aebf
3
+ metadata.gz: 4ded32ce5b0d65a2b0a7822002aafcef4169ef44
4
+ data.tar.gz: 9539d0cb82f90cb3c2870f2df978587225bd7123
5
5
  SHA512:
6
- metadata.gz: d041a8329f0bd72c8fff3d2d7463810222aedbeb806856fcf84b8a04b3aac9fe52a4d81cf494d9baf1db74a93d125a07029a93057df6388b5c15c1811e6791d9
7
- data.tar.gz: 6b0ac0586984255775ea12f64bf834e4900c65d3ea26d3e1409bfc8f1270d85784abdbd54367e8ccfc1dfefe752572cdd8d13af0b145ae1d0f68daec210c597d
6
+ metadata.gz: b003dca162b11cf53a47eea41d5a9d724bf78234a16f3ac95bca5d744079a04ec0438066e89cc4ae3a622b0aa0b4d03bdbd1aae47d0bccb5d18aa4d534f8f8eb
7
+ data.tar.gz: dd7902847f6026023de2e2d06b75fc73cbf47ad1e753b9731c082da47be4b4b48b3de5cd4ff9f1e89f17dd4424b518195e2c034c32cf13f8adac6a016bf9a461
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Loglevel
4
- VERSION = '0.2.1'.freeze
4
+ VERSION = '0.2.3'.freeze
5
5
  end
data/loglevel.gemspec CHANGED
@@ -11,13 +11,13 @@ Gem::Specification.new do |spec|
11
11
  spec.required_ruby_version = '>= 2.0.0'
12
12
  spec.authors = ['Dominic Sayers']
13
13
  spec.email = ['dominic@sayers.cc']
14
- spec.description = 'A simple gem to interact with Mailchimp through their API v3'
15
- spec.summary = 'Example: mailchimp.lists("My first list").member("ann@example.com")'
14
+ spec.description = 'A simple gem to control logging at runtime with an environment variable'
15
+ spec.summary = 'Example: LOGLEVEL=WARN rails server'
16
16
  spec.homepage = 'https://github.com/dominicsayers/loglevel'
17
17
  spec.license = 'MIT'
18
18
 
19
- spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
19
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR).reject { |f| f =~ %r{^spec/} }
20
20
  spec.executables = spec.files.grep(%r{^bin\/}) { |f| File.basename(f) }
21
- spec.test_files = spec.files.grep(%r{^(test|spec|features|coverage|script)\/})
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features|coverage|script)/})
22
22
  spec.require_paths = ['lib']
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loglevel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominic Sayers
@@ -10,7 +10,7 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2017-03-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A simple gem to interact with Mailchimp through their API v3
13
+ description: A simple gem to control logging at runtime with an environment variable
14
14
  email:
15
15
  - dominic@sayers.cc
16
16
  executables: []
@@ -39,12 +39,6 @@ files:
39
39
  - lib/loglevel/version.rb
40
40
  - loglevel.gemspec
41
41
  - script/console
42
- - spec/loglevel/active_record_spec.rb
43
- - spec/loglevel/classes_spec.rb
44
- - spec/loglevel/help_spec.rb
45
- - spec/loglevel/http_logger_spec.rb
46
- - spec/loglevel_spec.rb
47
- - spec/spec_helper.rb
48
42
  homepage: https://github.com/dominicsayers/loglevel
49
43
  licenses:
50
44
  - MIT
@@ -68,12 +62,6 @@ rubyforge_project:
68
62
  rubygems_version: 2.6.11
69
63
  signing_key:
70
64
  specification_version: 4
71
- summary: 'Example: mailchimp.lists("My first list").member("ann@example.com")'
65
+ summary: 'Example: LOGLEVEL=WARN rails server'
72
66
  test_files:
73
67
  - script/console
74
- - spec/loglevel/active_record_spec.rb
75
- - spec/loglevel/classes_spec.rb
76
- - spec/loglevel/help_spec.rb
77
- - spec/loglevel/http_logger_spec.rb
78
- - spec/loglevel_spec.rb
79
- - spec/spec_helper.rb
@@ -1,43 +0,0 @@
1
- require 'logger'
2
-
3
- RSpec.describe Loglevel::ActiveRecord do
4
- before do
5
- class MyClass
6
- class << self
7
- attr_accessor :logger
8
- end
9
- end
10
-
11
- class Rails < MyClass; end
12
-
13
- module ActiveRecord
14
- class Base < Rails; end
15
- end
16
-
17
- class HttpLogger < Rails
18
- class << self
19
- attr_accessor :level, :log_response_body, :log_headers, :ignore
20
- end
21
- end
22
- end
23
-
24
- after do
25
- Object.send(:remove_const, :MyClass)
26
- Object.send(:remove_const, :Rails)
27
- Object.send(:remove_const, :ActiveRecord)
28
- Object.send(:remove_const, :HttpLogger)
29
- end
30
-
31
- context 'NOAR' do
32
- let(:loglevel) { Loglevel.setup }
33
-
34
- before { ENV.store Loglevel::ENV_VAR_LEVEL, 'noAR' } # the capitalization is intentional
35
- after { ENV.delete Loglevel::ENV_VAR_LEVEL }
36
-
37
- it 'has the expected ActiveRecord settings' do
38
- loglevel # force instantiation
39
- expect(::ActiveRecord::Base.logger).to eq loglevel.send(:null_logger)
40
- expect(::ActiveRecord::Base.logger.level).to eq ::Logger.const_get('FATAL')
41
- end
42
- end
43
- end
@@ -1,44 +0,0 @@
1
- RSpec.describe Loglevel::Classes do
2
- context 'default classes' do
3
- it 'is empty unless classes are available' do
4
- expect(Loglevel::Classes.new.classes).to be_empty
5
- end
6
-
7
- it 'returns available classes' do
8
- class Rails; end
9
- class HttpLogger; end
10
-
11
- classes = Loglevel::Classes.new
12
- expect(classes.classes).to include(Rails, HttpLogger)
13
- expect(classes.stringify).to include('Rails', 'HttpLogger')
14
- expect(classes.stringify).not_to include('ActiveRecord::Base')
15
-
16
- Object.send(:remove_const, :Rails)
17
- Object.send(:remove_const, :HttpLogger)
18
- end
19
- end
20
-
21
- context 'classes from environment variable' do
22
- before { ENV.store Loglevel::ENV_VAR_CLASSES, 'String,Array , Hash,MyClass' } # the spaces are intentional
23
- after { ENV.delete Loglevel::ENV_VAR_CLASSES }
24
-
25
- it 'returns classes that exist' do
26
- classes = Loglevel::Classes.new
27
- expect(classes.classes).to include(String, Array, Hash)
28
- expect(classes.stringify).not_to include('MyClass')
29
- end
30
-
31
- it 'returns defined classes' do
32
- class MyClass; end
33
-
34
- module ActiveRecord
35
- class Base; end
36
- end
37
-
38
- expect(Loglevel::Classes.new.classes).to include(ActiveRecord::Base, String, Array, Hash, MyClass)
39
-
40
- Object.send(:remove_const, :MyClass)
41
- Object.send(:remove_const, :ActiveRecord)
42
- end
43
- end
44
- end
@@ -1,78 +0,0 @@
1
- RSpec.describe Loglevel::Help do
2
- context 'HELP' do
3
- before do
4
- class MyLogDevice
5
- attr_reader :filename, :dev
6
-
7
- def initialize(device)
8
- @dev = device
9
- end
10
- end
11
-
12
- class MyLogger
13
- INFO = 1
14
- attr_accessor :level
15
-
16
- def initialize(device)
17
- @logdev = MyLogDevice.new(device)
18
- end
19
-
20
- def info(message); end
21
- end
22
-
23
- ENV.store Loglevel::ENV_VAR_LOGGER, 'MyLogger'
24
- ENV.store Loglevel::ENV_VAR_DEVICE, 'MyDevice'
25
- ENV.store Loglevel::ENV_VAR_LEVEL, 'Help' # the capitalization is intentional
26
- end
27
-
28
- after do
29
- ENV.delete Loglevel::ENV_VAR_LOGGER
30
- ENV.delete Loglevel::ENV_VAR_DEVICE
31
- ENV.delete Loglevel::ENV_VAR_LEVEL
32
- Object.send(:remove_const, :MyLogger)
33
- Object.send(:remove_const, :MyLogDevice)
34
- end
35
-
36
- it 'has the expected ActiveRecord settings' do
37
- expect_any_instance_of(MyLogger).to receive(:info).once
38
- Loglevel.setup
39
- end
40
-
41
- it 'shows information about itself' do
42
- expect(Loglevel.setup.inspect).to eq(
43
- '#<Loglevel: logger=MyLogger, device=MyDevice, level=INFO, settings=["HELP"]>'
44
- )
45
- end
46
-
47
- it 'shows debugging information about itself' do
48
- class MyClass
49
- class << self
50
- attr_accessor :logger
51
- end
52
- end
53
-
54
- class Rails < MyClass; end
55
-
56
- module ActiveRecord
57
- class Base < Rails; end
58
- end
59
-
60
- class HttpLogger < Rails
61
- class << self
62
- attr_accessor :level, :log_response_body, :log_headers, :ignore
63
- end
64
- end
65
-
66
- expect(Loglevel.setup.debug).to eq <<-DEBUG.gsub(' ', '').chomp
67
- Rails: logger=MyLogger, device=MyDevice, level=INFO
68
- ActiveRecord::Base: logger=MyLogger, device=MyDevice, level=INFO
69
- HttpLogger: logger=MyLogger, device=MyDevice, level=INFO
70
- DEBUG
71
-
72
- Object.send(:remove_const, :MyClass)
73
- Object.send(:remove_const, :Rails)
74
- Object.send(:remove_const, :ActiveRecord)
75
- Object.send(:remove_const, :HttpLogger)
76
- end
77
- end
78
- end
@@ -1,43 +0,0 @@
1
- require 'logger'
2
-
3
- RSpec.describe Loglevel::HttpLogger do
4
- before do
5
- class MyClass
6
- class << self
7
- attr_accessor :logger
8
- end
9
- end
10
-
11
- class Rails < MyClass; end
12
-
13
- module ActiveRecord
14
- class Base < Rails; end
15
- end
16
-
17
- class HttpLogger < Rails
18
- class << self
19
- attr_accessor :level, :log_response_body, :log_headers, :ignore
20
- end
21
- end
22
- end
23
-
24
- after do
25
- Object.send(:remove_const, :MyClass)
26
- Object.send(:remove_const, :Rails)
27
- Object.send(:remove_const, :ActiveRecord)
28
- Object.send(:remove_const, :HttpLogger)
29
- end
30
-
31
- context 'NOHTTP' do
32
- let(:loglevel) { Loglevel.setup }
33
-
34
- before { ENV.store Loglevel::ENV_VAR_LEVEL, 'NoHttp' } # the capitalization is intentional
35
- after { ENV.delete Loglevel::ENV_VAR_LEVEL }
36
-
37
- it 'has the expected HttpLogger settings' do
38
- loglevel # force instantiation
39
- expect(::HttpLogger.logger).to eq loglevel.send(:null_logger)
40
- expect(::HttpLogger.level).to eq :fatal
41
- end
42
- end
43
- end
@@ -1,176 +0,0 @@
1
- require 'logger'
2
-
3
- RSpec.describe Loglevel do
4
- before do
5
- class MyClass
6
- class << self
7
- attr_accessor :logger
8
- end
9
- end
10
-
11
- class Rails < MyClass; end
12
-
13
- module ActiveRecord
14
- class Base < Rails; end
15
- end
16
-
17
- class HttpLogger < Rails
18
- class << self
19
- attr_accessor :level, :log_response_body, :log_headers, :ignore
20
- end
21
- end
22
- end
23
-
24
- after do
25
- Object.send(:remove_const, :MyClass)
26
- Object.send(:remove_const, :Rails)
27
- Object.send(:remove_const, :ActiveRecord)
28
- Object.send(:remove_const, :HttpLogger)
29
- end
30
-
31
- context 'no environment variable' do
32
- let(:loglevel) { Loglevel.setup }
33
-
34
- it 'has the expected logger class' do
35
- expect(loglevel.send(:logger_class)).to eq ::Logger
36
- end
37
-
38
- it 'has the expected device' do
39
- expect(loglevel.send(:device)).to eq STDOUT
40
- end
41
-
42
- it 'has the expected log level' do
43
- expect(Rails.logger).to be_nil
44
- end
45
-
46
- it 'has the expected ActiveRecord::Base settings' do
47
- expect(::ActiveRecord::Base.logger).to be_nil
48
- end
49
-
50
- it 'has the expected HttpLogger settings' do
51
- expect(::HttpLogger.level).to be_nil
52
- expect(::HttpLogger.log_response_body).to be_nil
53
- expect(::HttpLogger.log_headers).to be_nil
54
- expect(::HttpLogger.ignore).to be_nil
55
- end
56
- end
57
-
58
- context 'defaults' do
59
- let(:loglevel) { Loglevel.setup }
60
-
61
- before { ENV.store Loglevel::ENV_VAR_LEVEL, 'INFO' }
62
- after { ENV.delete Loglevel::ENV_VAR_LEVEL }
63
-
64
- it 'has the expected logger class' do
65
- expect(loglevel.send(:logger_class)).to eq ::Logger
66
- end
67
-
68
- it 'has the expected device' do
69
- expect(loglevel.send(:device)).to eq STDOUT
70
- end
71
-
72
- it 'has the expected log level' do
73
- loglevel # force instantiation
74
- expect(Rails.logger).to eq loglevel.logger
75
- expect(Rails.logger.level).to eq ::Logger.const_get('INFO')
76
- end
77
-
78
- it 'has the expected ActiveRecord::Base settings' do
79
- loglevel # force instantiation
80
- expect(::ActiveRecord::Base.logger).to eq loglevel.logger
81
- expect(::ActiveRecord::Base.logger.level).to eq ::Logger.const_get('INFO')
82
- end
83
-
84
- it 'has the expected HttpLogger settings' do
85
- loglevel # force instantiation
86
- expect(::HttpLogger.level).to eq :info
87
- expect(::HttpLogger.log_response_body).to be_truthy
88
- expect(::HttpLogger.log_headers).to be_truthy
89
- expect(::HttpLogger.ignore).to include(/9200/, /7474/)
90
- end
91
- end
92
-
93
- context 'variations' do
94
- before do
95
- class MyLogger
96
- INFO = 1
97
- WARN = 2
98
- FATAL = 4
99
- attr_accessor :level
100
- def initialize(device); end
101
- end
102
-
103
- ENV.store Loglevel::ENV_VAR_LOGGER, 'MyLogger'
104
- ENV.store Loglevel::ENV_VAR_DEVICE, 'STDERR'
105
- end
106
-
107
- after do
108
- ENV.delete Loglevel::ENV_VAR_LEVEL
109
- ENV.delete Loglevel::ENV_VAR_LOGGER
110
- ENV.delete Loglevel::ENV_VAR_DEVICE
111
- Object.send(:remove_const, :MyLogger)
112
- end
113
-
114
- context 'HTTP and ActiveRecord' do
115
- let(:loglevel) { Loglevel.setup }
116
-
117
- before { ENV.store Loglevel::ENV_VAR_LEVEL, 'WARN' }
118
- after { ENV.delete Loglevel::ENV_VAR_LEVEL }
119
-
120
- it 'has the expected logger class' do
121
- expect(loglevel.send(:logger_class)).to eq ::MyLogger
122
- end
123
-
124
- it 'has the expected device' do
125
- expect(loglevel.send(:device)).to eq STDERR
126
- end
127
-
128
- it 'has the expected log level' do
129
- loglevel # force instantiation
130
- expect(Rails.logger).to eq loglevel.logger
131
- expect(Rails.logger.level).to eq ::Logger.const_get('WARN')
132
- end
133
- end
134
-
135
- context 'HTTP but not ActiveRecord' do
136
- let(:loglevel) { Loglevel.setup }
137
-
138
- before { ENV.store Loglevel::ENV_VAR_LEVEL, 'WARN,NOBODY,NOHEADERS,NOAR' }
139
- after { ENV.delete Loglevel::ENV_VAR_LEVEL }
140
-
141
- it 'has the expected ActiveRecord::Base settings' do
142
- loglevel # force instantiation
143
- expect(::ActiveRecord::Base.logger).to eq loglevel.send(:null_logger)
144
- end
145
-
146
- it 'has the expected HttpLogger settings' do
147
- loglevel # force instantiation
148
- expect(::HttpLogger.level).to eq :warn
149
- expect(::HttpLogger.log_response_body).to be_falsey
150
- expect(::HttpLogger.log_headers).to be_falsey
151
- expect(::HttpLogger.ignore).to include(/9200/, /7474/)
152
- end
153
- end
154
-
155
- context 'ActiveRecord but not HTTP' do
156
- let(:loglevel) { Loglevel.setup }
157
-
158
- before { ENV.store Loglevel::ENV_VAR_LEVEL, 'WARN,NOHTTP' }
159
- after { ENV.delete Loglevel::ENV_VAR_LEVEL }
160
-
161
- it 'has the expected ActiveRecord::Base settings' do
162
- loglevel # force instantiation
163
- expect(::ActiveRecord::Base.logger).to eq loglevel.logger
164
- expect(::ActiveRecord::Base.logger.level).to eq ::Logger.const_get('WARN')
165
- end
166
-
167
- it 'has the expected HttpLogger settings' do
168
- loglevel # force instantiation
169
- expect(::HttpLogger.level).to eq :fatal
170
- expect(::HttpLogger.log_response_body).to be_falsey
171
- expect(::HttpLogger.log_headers).to be_falsey
172
- expect(::HttpLogger.ignore).to be_nil
173
- end
174
- end
175
- end
176
- end
data/spec/spec_helper.rb DELETED
@@ -1,110 +0,0 @@
1
- # Configure Simplecov and Coveralls
2
- unless ENV['NO_SIMPLECOV']
3
- require 'simplecov'
4
- require 'coveralls'
5
-
6
- SimpleCov.start { add_filter '/spec/' }
7
- Coveralls.wear! if ENV['COVERALLS_REPO_TOKEN']
8
- end
9
-
10
- require 'loglevel'
11
-
12
- # This file was generated by the `rspec --init` command. Conventionally, all
13
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
14
- # The generated `.rspec` file contains `--require spec_helper` which will cause
15
- # this file to always be loaded, without a need to explicitly require it in any
16
- # files.
17
- #
18
- # Given that it is always loaded, you are encouraged to keep this file as
19
- # light-weight as possible. Requiring heavyweight dependencies from this file
20
- # will add to the boot time of your test suite on EVERY test run, even for an
21
- # individual file that may not need all of that loaded. Instead, consider making
22
- # a separate helper file that requires the additional dependencies and performs
23
- # the additional setup, and require it from the spec files that actually need
24
- # it.
25
- #
26
- # The `.rspec` file also contains a few flags that are not defaults but that
27
- # users commonly want.
28
- #
29
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
30
- RSpec.configure do |config|
31
- # rspec-expectations config goes here. You can use an alternate
32
- # assertion/expectation library such as wrong or the stdlib/minitest
33
- # assertions if you prefer.
34
- config.expect_with :rspec do |expectations|
35
- # This option will default to `true` in RSpec 4. It makes the `description`
36
- # and `failure_message` of custom matchers include text for helper methods
37
- # defined using `chain`, e.g.:
38
- # be_bigger_than(2).and_smaller_than(4).description
39
- # # => "be bigger than 2 and smaller than 4"
40
- # ...rather than:
41
- # # => "be bigger than 2"
42
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
43
- end
44
-
45
- # rspec-mocks config goes here. You can use an alternate test double
46
- # library (such as bogus or mocha) by changing the `mock_with` option here.
47
- config.mock_with :rspec do |mocks|
48
- # Prevents you from mocking or stubbing a method that does not exist on
49
- # a real object. This is generally recommended, and will default to
50
- # `true` in RSpec 4.
51
- mocks.verify_partial_doubles = true
52
- end
53
-
54
- # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
55
- # have no way to turn it off -- the option exists only for backwards
56
- # compatibility in RSpec 3). It causes shared context metadata to be
57
- # inherited by the metadata hash of host groups and examples, rather than
58
- # triggering implicit auto-inclusion in groups with matching metadata.
59
- config.shared_context_metadata_behavior = :apply_to_host_groups
60
-
61
- # This allows you to limit a spec run to individual examples or groups
62
- # you care about by tagging them with `:focus` metadata. When nothing
63
- # is tagged with `:focus`, all examples get run. RSpec also provides
64
- # aliases for `it`, `describe`, and `context` that include `:focus`
65
- # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
66
- config.filter_run_when_matching :focus
67
-
68
- # Allows RSpec to persist some state between runs in order to support
69
- # the `--only-failures` and `--next-failure` CLI options. We recommend
70
- # you configure your source control system to ignore this file.
71
- config.example_status_persistence_file_path = 'tmp/rspec/examples.txt'
72
-
73
- # Limits the available syntax to the non-monkey patched syntax that is
74
- # recommended. For more details, see:
75
- # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
76
- # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
77
- # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
78
- config.disable_monkey_patching!
79
-
80
- # This setting enables warnings. It's recommended, but in some cases may
81
- # be too noisy due to issues in dependencies.
82
- config.warnings = true
83
-
84
- # Many RSpec users commonly either run the entire suite or an individual
85
- # file, and it's useful to allow more verbose output when running an
86
- # individual spec file.
87
- if config.files_to_run.one?
88
- # Use the documentation formatter for detailed output,
89
- # unless a formatter has already been configured
90
- # (e.g. via a command-line flag).
91
- config.default_formatter = 'doc'
92
- end
93
-
94
- # Print the 10 slowest examples and example groups at the
95
- # end of the spec run, to help surface which specs are running
96
- # particularly slow.
97
- config.profile_examples = 10
98
-
99
- # Run specs in random order to surface order dependencies. If you find an
100
- # order dependency and want to debug it, you can fix the order by providing
101
- # the seed, which is printed after each run.
102
- # --seed 1234
103
- config.order = :random
104
-
105
- # Seed global randomization in this process using the `--seed` CLI option.
106
- # Setting this allows you to use `--seed` to deterministically reproduce
107
- # test failures related to randomization by passing the same `--seed` value
108
- # as the one that triggered the failure.
109
- Kernel.srand config.seed
110
- end