loglevel 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f7aa16f419c37f168c98409956cfa25b9cee845
4
- data.tar.gz: 0ada2cc16ef1b3fa9527c438e26858d4dae83cea
3
+ metadata.gz: '029c298d5ce2f964647c947a95ef214d6e5d207e'
4
+ data.tar.gz: d5ea7fa65220d6a76e5ca9ed49f0526bcfc86747
5
5
  SHA512:
6
- metadata.gz: dab91b3da3a07b99134fe9bec53ac2a2020d9edf37b7dcc1c94f0b254c90a4221aea2ea065545e19a4ec74b0b5e70775ff6071a090112d40358a418dfb941454
7
- data.tar.gz: 0eff2e99f03b5d23abb3f65382996f5681fed4c53e5bad3e8514bcbc4bc0598eb1e29a996f7ab71f8a3f71580b96fde0c9be0c4cd9f68779d206bf9126517440
6
+ metadata.gz: 0fee1924b678abc449656572d8103141563cf35dde619e94ecd6e80ca17a885ca5775e5593d53c70a30408fd1aeba82824f50419540e828924353ce3c2ee1e67
7
+ data.tar.gz: c109086212ea09e5b46d188a1147c8492697d13f1b541e692597c2c634932822abad34d495c7e19777a4fab1b02e74e29c8673870c576730fd294a12c6fc4426
data/.rubocop.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  ---
2
+ require: rubocop-rspec
3
+
2
4
  AllCops:
3
- TargetRubyVersion: 2.0
5
+ TargetRubyVersion: 2.2
4
6
  DisplayCopNames: true
5
7
  Exclude:
6
8
  - 'tmp/**/*'
@@ -19,21 +21,17 @@ StringLiterals:
19
21
  Enabled: true
20
22
 
21
23
  DotPosition:
22
- Description: 'Checks the position of the dot in multi-line method calls.'
23
24
  EnforcedStyle: leading
24
25
  Enabled: true
25
26
 
26
27
  ClassAndModuleChildren:
27
- Description: 'Checks style of children classes and modules.'
28
28
  EnforcedStyle: nested
29
29
  Enabled: true
30
30
 
31
31
  Documentation:
32
- Description: 'Document classes and non-namespace modules.'
33
32
  Enabled: false
34
33
 
35
34
  FileName:
36
- Description: 'Use snake_case for source file names.'
37
35
  Enabled: true
38
36
 
39
37
  LineLength:
@@ -41,11 +39,9 @@ LineLength:
41
39
  Enabled: true
42
40
 
43
41
  Style/ExtraSpacing:
44
- Description: 'Do not use unnecessary spacing.'
45
42
  Enabled: true
46
43
 
47
44
  Lint/LiteralInInterpolation:
48
- Description: 'Avoid interpolating literals in strings'
49
45
  AutoCorrect: true
50
46
 
51
47
  Style/ModuleFunction:
data/CHANGELOG.md CHANGED
@@ -1,8 +1,58 @@
1
1
  # Change Log
2
2
 
3
- ## [Unreleased](https://github.com/dominicsayers/loglevel/tree/HEAD)
3
+ ## [v1.0.1](https://github.com/dominicsayers/loglevel/tree/v1.0.1) (2017-05-03)
4
+ [Full Changelog](https://github.com/dominicsayers/loglevel/compare/v1.0.0...v1.0.1)
4
5
 
5
- [Full Changelog](https://github.com/dominicsayers/loglevel/compare/v0.1.1...HEAD)
6
+ **Closed issues:**
7
+
8
+ - Include the rubocop rspec gem and improve the code quality of the specs [\#5](https://github.com/dominicsayers/loglevel/issues/5)
9
+
10
+ **Merged pull requests:**
11
+
12
+ - Release v1.0.1 [\#6](https://github.com/dominicsayers/loglevel/pull/6) ([dominicsayers](https://github.com/dominicsayers))
13
+
14
+ ## [v1.0.0](https://github.com/dominicsayers/loglevel/tree/v1.0.0) (2017-04-12)
15
+ [Full Changelog](https://github.com/dominicsayers/loglevel/compare/v0.4.6...v1.0.0)
16
+
17
+ **Merged pull requests:**
18
+
19
+ - Refactor to simplify class structure [\#3](https://github.com/dominicsayers/loglevel/pull/3) ([dominicsayers](https://github.com/dominicsayers))
20
+
21
+ ## [v0.4.6](https://github.com/dominicsayers/loglevel/tree/v0.4.6) (2017-04-11)
22
+ [Full Changelog](https://github.com/dominicsayers/loglevel/compare/v0.4.5...v0.4.6)
23
+
24
+ ## [v0.4.5](https://github.com/dominicsayers/loglevel/tree/v0.4.5) (2017-04-10)
25
+ [Full Changelog](https://github.com/dominicsayers/loglevel/compare/v0.4.4...v0.4.5)
26
+
27
+ ## [v0.4.4](https://github.com/dominicsayers/loglevel/tree/v0.4.4) (2017-04-10)
28
+ [Full Changelog](https://github.com/dominicsayers/loglevel/compare/v0.4.2...v0.4.4)
29
+
30
+ ## [v0.4.2](https://github.com/dominicsayers/loglevel/tree/v0.4.2) (2017-04-10)
31
+ [Full Changelog](https://github.com/dominicsayers/loglevel/compare/v0.4.1...v0.4.2)
32
+
33
+ ## [v0.4.1](https://github.com/dominicsayers/loglevel/tree/v0.4.1) (2017-04-10)
34
+ [Full Changelog](https://github.com/dominicsayers/loglevel/compare/v0.4.0...v0.4.1)
35
+
36
+ ## [v0.4.0](https://github.com/dominicsayers/loglevel/tree/v0.4.0) (2017-04-10)
37
+ [Full Changelog](https://github.com/dominicsayers/loglevel/compare/v0.3.0...v0.4.0)
38
+
39
+ ## [v0.3.0](https://github.com/dominicsayers/loglevel/tree/v0.3.0) (2017-04-05)
40
+ [Full Changelog](https://github.com/dominicsayers/loglevel/compare/v0.2.4...v0.3.0)
41
+
42
+ ## [v0.2.4](https://github.com/dominicsayers/loglevel/tree/v0.2.4) (2017-04-01)
43
+ [Full Changelog](https://github.com/dominicsayers/loglevel/compare/v0.2.3...v0.2.4)
44
+
45
+ ## [v0.2.3](https://github.com/dominicsayers/loglevel/tree/v0.2.3) (2017-03-31)
46
+ [Full Changelog](https://github.com/dominicsayers/loglevel/compare/v0.2.2...v0.2.3)
47
+
48
+ ## [v0.2.2](https://github.com/dominicsayers/loglevel/tree/v0.2.2) (2017-03-31)
49
+ [Full Changelog](https://github.com/dominicsayers/loglevel/compare/v0.2.1...v0.2.2)
50
+
51
+ ## [v0.2.1](https://github.com/dominicsayers/loglevel/tree/v0.2.1) (2017-03-31)
52
+ [Full Changelog](https://github.com/dominicsayers/loglevel/compare/v0.2.0...v0.2.1)
53
+
54
+ ## [v0.2.0](https://github.com/dominicsayers/loglevel/tree/v0.2.0) (2017-03-31)
55
+ [Full Changelog](https://github.com/dominicsayers/loglevel/compare/v0.1.1...v0.2.0)
6
56
 
7
57
  **Merged pull requests:**
8
58
 
@@ -18,4 +68,4 @@
18
68
  ## [v0.1.0](https://github.com/dominicsayers/loglevel/tree/v0.1.0) (2017-03-29)
19
69
 
20
70
 
21
- \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
71
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/Gemfile CHANGED
@@ -1,24 +1,23 @@
1
- # frozen_string_literal: true
2
-
3
1
  source 'https://rubygems.org'
4
2
  gemspec
5
3
  ruby RUBY_VERSION
6
4
 
7
5
  group :development do
8
- gem 'bundler'
9
- gem 'gem-release'
10
- gem 'github_changelog_generator'
11
- gem 'guard'
12
- gem 'guard-rspec'
13
- gem 'guard-rubocop'
6
+ gem 'bundler', require: false
7
+ gem 'gem-release', require: false
8
+ gem 'github_changelog_generator', require: false
9
+ gem 'guard', require: false
10
+ gem 'guard-rspec', require: false
11
+ gem 'guard-rubocop', require: false
12
+ gem 'guard-rubycritic', require: false
13
+ gem 'rubocop-rspec', require: false
14
14
  end
15
15
 
16
16
  group :test do
17
- gem 'codeclimate-test-reporter'
18
- gem 'coveralls'
19
- gem 'fuubar'
20
- gem 'rake' # Workaround for a bug in Rainbow 2.2.1 https://github.com/sickill/rainbow/issues/44
21
- gem 'rspec'
22
- gem 'rspec_junit_formatter'
23
- gem 'simplecov'
17
+ gem 'codeclimate-test-reporter', require: false
18
+ gem 'coveralls', require: false
19
+ gem 'fuubar', require: false
20
+ gem 'rspec', require: false
21
+ gem 'rspec_junit_formatter', require: false
22
+ gem 'simplecov', '~> 0.14', require: false
24
23
  end
data/Guardfile CHANGED
@@ -1,10 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- guard :rubocop do
4
- watch(/.+\.rb$/)
5
- watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
6
- end
7
-
8
1
  guard(
9
2
  :rspec,
10
3
  all_after_pass: true,
@@ -12,7 +5,17 @@ guard(
12
5
  cmd: 'NO_SIMPLECOV=true bundle exec rspec --fail-fast --format documentation'
13
6
  ) do
14
7
  watch(%r{spec/.+_spec\.rb$})
15
- watch(%r{lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
8
+ watch(%r{lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
16
9
  watch('spec/spec_helper.rb') { 'spec' }
17
10
  watch(%r{^spec/support/.+\.rb$}) { 'spec' }
18
11
  end
12
+
13
+ guard :rubocop do
14
+ watch(/.+\.rb$/)
15
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
16
+ end
17
+
18
+ guard :rubycritic do
19
+ watch(%r{^app/(.+)\.rb$})
20
+ watch(%r{^lib/(.+)\.rb$})
21
+ end
data/README.md CHANGED
@@ -36,7 +36,6 @@ Here are the available settings:
36
36
 
37
37
  | Option | Description |
38
38
  | --------- | ------------------------------------------- |
39
- | HELP | Show these options |
40
39
  | FATAL | Equivalent to config.log_level = :fatal |
41
40
  | ERROR | Equivalent to config.log_level = :error |
42
41
  | WARN | Equivalent to config.log_level = :warn |
data/lib/loglevel.rb CHANGED
@@ -2,15 +2,17 @@ require 'loglevel/exception'
2
2
  require 'loglevel/constants'
3
3
  require 'loglevel/loggable_classes'
4
4
 
5
+ # Sets up any loggable classes to the log level you specify in an environment
6
+ # variable
5
7
  module Loglevel
6
8
  extend self
7
9
 
8
10
  def setup
9
- loggable_classes.each(&:setup)
11
+ loggable_classes.each(&:check)
10
12
  end
11
13
 
12
14
  def debug
13
- loggable_classes.map { |c| { name: c.class_name, logger: c.logger.class, level: c.level.level_name } }
15
+ loggable_classes.map(&:debug)
14
16
  end
15
17
 
16
18
  def device
@@ -20,10 +22,4 @@ module Loglevel
20
22
  def loggable_classes
21
23
  @loggable_classes ||= LoggableClasses.clone # More testable
22
24
  end
23
-
24
- def name_to_class(class_name, exception_class)
25
- Object.const_get(class_name)
26
- rescue NameError => exception
27
- Loglevel::Exception.handle_bad_class(class_name, exception, exception_class)
28
- end
29
25
  end
@@ -1,6 +1,7 @@
1
+ # :reek:TooManyConstants { max_constants: 7 }
1
2
  module Loglevel
2
3
  LOGLEVELS = %w[DEBUG INFO WARN ERROR FATAL UNKNOWN].freeze
3
- LOGLEVELS.each_with_index { |k, v| const_set(k, v) }
4
+ LOGLEVELS.each_with_index { |key, value| const_set(key, value) }
4
5
 
5
6
  ENV_VAR_LEVEL = 'LOGLEVEL'.freeze
6
7
  ENV_VAR_LOGGER = 'LOGGER'.freeze
@@ -1,15 +1,16 @@
1
1
  module Loglevel
2
2
  # Local exception classes to make handling exceptions easier
3
3
  class Exception < RuntimeError
4
+ # We've been asked to setting up logging for an unknown class
4
5
  UnknownLoggableClass = Class.new(self)
6
+ # We can't instantiate the defined logger class
5
7
  UnknownLoggerClass = Class.new(self)
8
+ # The class we've been asked to set up logging for doesn't understand
9
+ # logging
6
10
  ClassNotLoggable = Class.new(self)
7
11
 
8
12
  def self.handle_bad_class(class_name, exception, exception_class)
9
- raise exception unless exception.class == NameError &&
10
- class_name.respond_to?(:split) &&
11
- exception.message =~ /.+constant.+#{class_name.split(Loglevel::SRO).first}/
12
-
13
+ raise exception unless exception.class == NameError && exception.message =~ /.+constant.+/
13
14
  raise exception_class, class_name
14
15
  end
15
16
  end
@@ -2,15 +2,14 @@ require 'loglevel/loggable_class/level'
2
2
  require 'loglevel/loggable_class/smart_logger'
3
3
 
4
4
  module Loglevel
5
+ # An instance of a class that can be logged, i.e. has a #logger and a #logger=
6
+ # method
5
7
  class LoggableClass
6
8
  attr_reader :class_name, :logger
7
9
  alias to_s class_name
8
10
 
9
- def setup
10
- self.logger = smart_logger.create
11
- logger.level = level.value
12
- klass.logger = logger
13
- additional_http_setup
11
+ def check
12
+ # No checks implemented yet
14
13
  end
15
14
 
16
15
  def level
@@ -25,18 +24,39 @@ module Loglevel
25
24
  @http ||= canonical_name == '::HttpLogger'
26
25
  end
27
26
 
27
+ def debug
28
+ { name: class_name, logger: logger.class, level: level.level_name }
29
+ end
30
+
28
31
  private
29
32
 
30
33
  attr_writer :logger
31
34
 
32
35
  def initialize(class_name)
33
36
  @class_name = class_name
34
- raise Loglevel::Exception::ClassNotLoggable, class_name unless klass.respond_to?(:logger=)
37
+ http? ? http_setup : regular_setup
38
+ rescue NoMethodError => exception
39
+ raise unless exception.message =~ /undefined method `logger='/
40
+ raise Loglevel::Exception::ClassNotLoggable, class_name
35
41
  end
36
42
 
37
- def additional_http_setup
38
- return unless http?
43
+ # Setup for regular classes where we are setting the level of message we
44
+ # want to see
45
+ def regular_setup
46
+ self.logger = smart_logger
47
+ logger.level = level.value
48
+ klass.logger = logger
49
+ end
50
+
51
+ # Setup for HttpLogger. Here we are setting the level at which to log HTTP
52
+ # interactions
53
+ def http_setup
54
+ return unless http? && settings.http?
55
+ regular_setup
56
+ additional_http_setup
57
+ end
39
58
 
59
+ def additional_http_setup
40
60
  klass.level = level.level_name.downcase.to_sym
41
61
  klass.log_response_body = settings.response_body?
42
62
  klass.log_headers = settings.request_headers?
@@ -44,11 +64,13 @@ module Loglevel
44
64
  end
45
65
 
46
66
  def klass
47
- @klass ||= Loglevel.name_to_class(canonical_name, Loglevel::Exception::UnknownLoggableClass)
67
+ @klass ||= canonical_name.to_class Loglevel::Exception::UnknownLoggableClass
48
68
  end
49
69
 
50
70
  def canonical_name
51
- @canonical_name ||= class_name[0, 2] == Loglevel::SRO ? class_name : "#{Loglevel::SRO}#{class_name}"
71
+ @canonical_name ||= Loglevel::Name.new(
72
+ class_name[0, 2] == Loglevel::SRO ? class_name : "#{Loglevel::SRO}#{class_name}"
73
+ )
52
74
  end
53
75
 
54
76
  def settings
@@ -56,7 +78,7 @@ module Loglevel
56
78
  end
57
79
 
58
80
  def smart_logger
59
- @smart_logger ||= SmartLogger.clone # More testable
81
+ @smart_logger ||= SmartLogger.clone.create # More testable
60
82
  end
61
83
  end
62
84
  end
@@ -2,6 +2,7 @@ require 'loglevel/settings'
2
2
 
3
3
  module Loglevel
4
4
  class LoggableClass
5
+ # The current log level
5
6
  class Level
6
7
  def value
7
8
  @value ||= Loglevel.const_get level_name
@@ -15,9 +16,7 @@ module Loglevel
15
16
 
16
17
  extend Forwardable
17
18
 
18
- def_delegators :loggable_class, :active_record?, :http?
19
-
20
- attr_reader :loggable_class
19
+ def_delegators :@loggable_class, :active_record?, :http?
21
20
 
22
21
  def initialize(loggable_class, settings = nil)
23
22
  @loggable_class = loggable_class
@@ -25,11 +24,11 @@ module Loglevel
25
24
  end
26
25
 
27
26
  def http_level_name
28
- @http_level_name ||= 'FATAL' if loggable_class.http? && !settings.http?
27
+ @http_level_name ||= 'DEBUG' if http? && !settings.http?
29
28
  end
30
29
 
31
30
  def active_record_level_name
32
- @active_record_level_name ||= 'FATAL' if loggable_class.active_record? && !settings.active_record?
31
+ @active_record_level_name ||= 'FATAL' if active_record? && !settings.active_record?
33
32
  end
34
33
 
35
34
  def environment_level_name
@@ -1,5 +1,6 @@
1
1
  module Loglevel
2
2
  class LoggableClass
3
+ # The most appropriate logging class for this environment
3
4
  class SmartLogger
4
5
  class << self
5
6
  def create
@@ -17,11 +18,11 @@ module Loglevel
17
18
  end
18
19
 
19
20
  def logger_class
20
- @logger_class ||= loglevel.name_to_class(class_name, Loglevel::Exception::UnknownLoggerClass)
21
+ @logger_class ||= class_name.to_class Loglevel::Exception::UnknownLoggerClass
21
22
  end
22
23
 
23
24
  def class_name
24
- @class_name ||= environment_class_name || rails_class_name || 'Logger'
25
+ @class_name ||= Loglevel::Name.new(environment_class_name || rails_class_name || 'Logger')
25
26
  end
26
27
 
27
28
  def environment_class_name
@@ -1,6 +1,9 @@
1
1
  require 'loglevel/loggable_class'
2
+ require 'loglevel/name'
2
3
 
3
4
  module Loglevel
5
+ # An enumerable holding all classes that can be logged in the current
6
+ # environment
4
7
  module LoggableClasses
5
8
  class << self
6
9
  extend Forwardable
@@ -0,0 +1,20 @@
1
+ module Loglevel
2
+ # Like a string, but it can safely instantiate a class from itself
3
+ class Name
4
+ extend Forwardable
5
+
6
+ def_delegators :@string, :to_str, :==
7
+
8
+ def to_class(exception_class)
9
+ Object.const_get(self)
10
+ rescue NameError => exception
11
+ Loglevel::Exception.handle_bad_class(self, exception, exception_class)
12
+ end
13
+
14
+ private
15
+
16
+ def initialize(string)
17
+ @string = string
18
+ end
19
+ end
20
+ end
@@ -1,4 +1,5 @@
1
1
  module Loglevel
2
+ # Parses the environment variable into usable settings
2
3
  module Settings
3
4
  extend self
4
5
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Loglevel
4
- VERSION = '1.0.0'.freeze
4
+ VERSION = '1.0.1'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loglevel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominic Sayers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-12 00:00:00.000000000 Z
11
+ date: 2017-05-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple gem to control logging at runtime with an environment variable
14
14
  email:
@@ -17,12 +17,12 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - .codeclimate.yml
21
- - .gitignore
22
- - .hound.yml
23
- - .rspec
24
- - .rubocop.yml
25
- - .travis.yml
20
+ - ".codeclimate.yml"
21
+ - ".gitignore"
22
+ - ".hound.yml"
23
+ - ".rspec"
24
+ - ".rubocop.yml"
25
+ - ".travis.yml"
26
26
  - CHANGELOG.md
27
27
  - CODE_OF_CONDUCT.md
28
28
  - Gemfile
@@ -38,6 +38,7 @@ files:
38
38
  - lib/loglevel/loggable_class/level.rb
39
39
  - lib/loglevel/loggable_class/smart_logger.rb
40
40
  - lib/loglevel/loggable_classes.rb
41
+ - lib/loglevel/name.rb
41
42
  - lib/loglevel/settings.rb
42
43
  - lib/loglevel/version.rb
43
44
  - loglevel.gemspec
@@ -52,12 +53,12 @@ require_paths:
52
53
  - lib
53
54
  required_ruby_version: !ruby/object:Gem::Requirement
54
55
  requirements:
55
- - - '>='
56
+ - - ">="
56
57
  - !ruby/object:Gem::Version
57
58
  version: 2.0.0
58
59
  required_rubygems_version: !ruby/object:Gem::Requirement
59
60
  requirements:
60
- - - '>='
61
+ - - ">="
61
62
  - !ruby/object:Gem::Version
62
63
  version: '0'
63
64
  requirements: []