lager 1.1.2.1 → 1.1.4.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ddc68c3afe5aa76a06167a875a6023bd06c2b4c9092f9ca2190cfad926ba7142
4
+ data.tar.gz: 7df85fefabc6f5bd0618d5c0b9a5c0005321ab7011e30648155463eaf8fafabd
5
+ SHA512:
6
+ metadata.gz: 8ed30f93d47d148cf4c980ab6508cd49dcb37e5bc319612dd516af3d3efdee283e72e7b01ff310d16d572daee9e88c254711aac199fb1cb2d30b7e2a7cb306c1
7
+ data.tar.gz: 77d2c837acfd89396f8e4ddf7492fbd0b14d4e3b0f22cdf2db4c61205465b3e474d29edb1055deb33d20464e5398ffa2865a3ffa9f88f137480a809b67cc13fd
data/README.md CHANGED
@@ -1,6 +1,17 @@
1
+ [![CI Status](https://github.com/rickhull/lager/actions/workflows/ci.yaml/badge.svg)](https://github.com/rickhull/lager/actions/workflows/ci.yaml)
2
+ [![Gem Version](https://badge.fury.io/rb/lager.svg)](http://badge.fury.io/rb/lager)
3
+ [![Code Climate](https://codeclimate.com/github/rickhull/lager/badges/gpa.svg)](https://codeclimate.com/github/rickhull/lager/badges)
4
+
1
5
  Lager
2
6
  =====
3
- Lager is a logging mixin. It is designed to add class methods for logging, via `extend Lager`. It provides a unified logging instance that you can use in both class and instance methods. It is implemented with the familiar [Logger class](http://ruby-doc.org/stdlib-2.0/libdoc/logger/rdoc/Logger.html) from ruby's [stdlib](http://ruby-doc.org/stdlib/). Only one Logger instance is used for the class. Use #log_to to set the log destination and log level from inside or outside the class.
7
+
8
+ Lager is a logging mixin. It is designed to add class methods for logging,
9
+ via `extend Lager`. It provides a unified logging instance that you can use
10
+ in both class and instance methods. It is implemented with the familiar
11
+ [Logger class](http://ruby-doc.org/stdlib-2.0/libdoc/logger/rdoc/Logger.html)
12
+ from ruby's [stdlib](http://ruby-doc.org/stdlib/). Only one Logger instance
13
+ is used for the class. Use `log_to` to set the log destination and log level
14
+ from inside or outside the class.
4
15
 
5
16
  Usage
6
17
  -----
@@ -13,7 +24,8 @@ class Foo
13
24
  # ...
14
25
  ```
15
26
 
16
- Now, within Foo, you can use the class instance variable @lager for logging.
27
+ Now, within Foo, you can use the class instance variable `@lager` for
28
+ logging.
17
29
 
18
30
  ```ruby
19
31
  # ...
@@ -25,7 +37,8 @@ Now, within Foo, you can use the class instance variable @lager for logging.
25
37
  # ...
26
38
  ```
27
39
 
28
- What about instance methods, you ask? Well, you will need to assign @lager yourself, within #initialize.
40
+ What about instance methods, you ask? Well, you will need to assign `@lager`
41
+ yourself, within `#initialize`.
29
42
 
30
43
  ```ruby
31
44
  # ...
@@ -57,7 +70,8 @@ f.do_something_complicated
57
70
  [2013-07-05 15:14:52] DEBUG: whew! we made it!
58
71
  ```
59
72
 
60
- This is because we set the default logging to :debug level, above. Let's calm things down a bit, shall we?
73
+ This is because we set the default logging to `:debug` level, above.
74
+ Let's calm things down a bit, shall we?
61
75
 
62
76
  ```ruby
63
77
  Foo.log_level = :warn
@@ -70,14 +84,18 @@ We can tell Foo to log to a file:
70
84
  Foo.log_to '/tmp/foo.log'
71
85
  ```
72
86
 
73
- Note that this will replace the class's Logger instance. The old log level will be maintained unless you specify a new one.
87
+ Note that this will replace the class's Logger instance. The old log level
88
+ will be maintained unless you specify a new one.
74
89
 
75
90
  Best practices
76
91
  --------------
77
- * Set default logging inside the class definition by calling log_to just after extend Lager
78
- * Set the instance layer's @lager within #initialize
79
- * Only call message methods (debug, info, warn, error, fatal) on @lager in your class and instance methods.
80
- * Beyond the class default, let the log destination and log level be managed from the outside, by the users of your class.
92
+ * Set default logging inside the class definition by calling `log_to`
93
+ just after `extend Lager`
94
+ * Set the instance layer's `@lager` within `#initialize`
95
+ * Only call message methods (debug, info, warn, error, fatal) on `@lager`
96
+ in your class and instance methods.
97
+ * Beyond the class default, let the log destination and log level be
98
+ managed from the outside, by the users of your class.
81
99
 
82
100
  For Logger, generally: use block invocation of message methods.
83
101
 
@@ -85,22 +103,23 @@ For Logger, generally: use block invocation of message methods.
85
103
  @lager.debug { "hi" }
86
104
  # rather than
87
105
  @lager.debug "hi"
88
-
89
- # By using the first form, the block will not be evaluated unless we
90
- # are logging at DEBUG level.
91
- # If using the second form, the message is evaluated no matter the current
92
- # log level. This can be significant when logging complicated messages.
93
106
  ```
94
107
 
108
+ By using the first form, the block will not be evaluated unless you are
109
+ logging at `DEBUG` level. If using the second form, the message is evaluated
110
+ no matter the current log level. This can be significant when logging heavily
111
+ processed messages.
112
+
95
113
  Artifacts
96
114
  ---------
97
- * By mixing in Lager via extend, you introduce these class methods:
115
+ * By mixing in via `extend Lager`, you introduce these class methods:
98
116
  * lager
99
117
  * log_to
100
118
  * log_level
101
119
  * log_level=
102
- * By calling log_to, you introduce the *class instance variable* @lager
103
- * By assigning @lager within initialize, you introduce the *instance variable* @lager
120
+ * By calling `log_to`, you introduce the *class instance variable* `@lager`
121
+ * By assigning `@lager` within `initialize`, you introduce the
122
+ *instance variable* `@lager`
104
123
 
105
124
  Now you have a unified interface for logging at both class and instance layers.
106
125
 
@@ -110,7 +129,8 @@ Now you have a unified interface for logging at both class and instance layers.
110
129
 
111
130
  Use an existing Logger instance
112
131
  -------------------------------
113
- If your project already has an existing Logger, then you can set your class to use that Logger:
132
+ If your project already has an existing Logger, then you can set your class
133
+ to use that Logger:
114
134
 
115
135
  ```ruby
116
136
  class Foo
@@ -120,7 +140,8 @@ class Foo
120
140
  end
121
141
  ```
122
142
 
123
- Of course, $LOG will have to have already been defined at requiretime. You can set it the same way at runtime:
143
+ Of course, `$LOG` will have to have already been defined at requiretime.
144
+ You can set it the same way at runtime:
124
145
 
125
146
  ```ruby
126
147
  class Foo
@@ -137,6 +158,7 @@ Foo.log_to Project.log
137
158
 
138
159
  Inheritance
139
160
  -----------
161
+
140
162
  ```ruby
141
163
  class Foo
142
164
  extend Lager
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'rake/testtask'
2
+
3
+ desc "Run tests"
4
+ Rake::TestTask.new :test do |t|
5
+ t.pattern = 'test/*.rb'
6
+ t.warning = true
7
+ end
8
+
9
+ task default: %w[test]
10
+
11
+ begin
12
+ require 'buildar'
13
+
14
+ Buildar.new do |b|
15
+ b.gemspec_file = 'lager.gemspec'
16
+ b.version_file = 'VERSION'
17
+ b.use_git = true
18
+ end
19
+ rescue LoadError
20
+ warn "buildar unavailble"
21
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2.1
1
+ 1.1.4.1
data/lager.gemspec CHANGED
@@ -1,21 +1,17 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'lager'
3
3
  s.summary = "Sane class-level logging"
4
+ s.description = "Should you use it? Yes."
4
5
  s.author = "Rick Hull"
5
6
  s.homepage = "http://github.com/rickhull/lager"
6
- s.license = 'LGPL'
7
- s.has_rdoc = true
8
- s.description = "Should you use it? Yes."
7
+ s.license = 'LGPL-3.0'
9
8
 
10
- s.add_development_dependency "minitest", [">= 0"]
11
- s.add_development_dependency "buildar", ["~> 1.4"]
9
+ s.required_ruby_version = '> 2'
12
10
 
13
- # dynamic setup
14
- this_dir = File.expand_path('..', __FILE__)
15
- version_file = File.join(this_dir, 'VERSION')
16
- manifest_file = File.join(this_dir, 'MANIFEST.txt')
11
+ s.version = File.read(File.join(__dir__, 'VERSION')).chomp
17
12
 
18
13
  # dynamic assignments
19
- s.version = File.read(version_file).chomp
20
- s.files = File.readlines(manifest_file).map { |f| f.chomp }
14
+ s.files = %w[lager.gemspec VERSION README.md Rakefile]
15
+ s.files += Dir['lib/**/*.rb']
16
+ s.files += Dir['test/**/*.rb']
21
17
  end
data/lib/lager.rb CHANGED
@@ -54,15 +54,15 @@ module Lager
54
54
  dest # don't expose @lager here
55
55
  end
56
56
 
57
- # call without argument to get the log level
58
- # call with argument to set the log level
59
- # :debug, 'debug', and Logger::DEBUG (0) are all supported
57
+ # returns a symbol e.g. :debug -- possibly :unknown
60
58
  #
61
59
  def log_level
62
60
  raise "no @lager available" unless defined?(@lager)
63
61
  [:debug, :info, :warn, :error, :fatal][@lager.level] || :unknown
64
62
  end
65
63
 
64
+ # :debug, 'debug', and Logger::DEBUG (0) are all supported
65
+ #
66
66
  def log_level=(level)
67
67
  raise "no @lager available" unless defined?(@lager)
68
68
  case level
@@ -87,7 +87,7 @@ module Lager
87
87
  # typically only used within initialize
88
88
  #
89
89
  def lager
90
- log_to unless defined?(@lager)
90
+ raise "no @lager available" unless defined?(@lager)
91
91
  @lager
92
92
  end
93
93
  end
data/test/lager.rb CHANGED
@@ -1,9 +1,6 @@
1
- require 'minitest/spec'
2
- require 'minitest/autorun'
3
-
4
1
  require 'tempfile'
5
-
6
- require_relative '../lib/lager'
2
+ require 'lager'
3
+ require 'minitest/autorun'
7
4
 
8
5
  # useful Foo class
9
6
  # calls log_to at require time
@@ -12,28 +9,28 @@ require_relative '../examples/foo'
12
9
 
13
10
  describe Lager do
14
11
  describe ".version" do
15
- it "must return a string of numbers and dots" do
16
- Lager.version.must_match %r{\A[0-9\.]+\z}
12
+ it "returns a string of numbers and dots" do
13
+ expect(Lager.version).must_match %r{\A[0-9\.]+\z}
17
14
  end
18
15
  end
19
16
 
20
17
  describe "#log_to" do
21
18
  it "must have created a Logger" do
22
19
  # note, the useful Foo class has already called log_to
23
- Foo.lager.must_be_instance_of(Logger)
20
+ expect(Foo.lager).must_be_instance_of(Logger)
24
21
  end
25
22
 
26
- it "must return nil" do
27
- Foo.log_to($stdout).must_equal $stdout
23
+ it "must return its argument" do
24
+ expect(Foo.log_to($stdout)).must_equal $stdout
28
25
  end
29
26
 
30
27
  it "must use an existing Logger when provided" do
31
28
  l = Logger.new($stderr)
32
29
  Foo.log_to l
33
- Foo.lager.must_equal l
30
+ expect(Foo.lager).must_equal l
34
31
  Foo.log_level = :info
35
32
  Foo.bar # does debug logging, should be silent
36
- Foo.lager.must_equal l
33
+ expect(Foo.lager).must_equal l
37
34
  end
38
35
 
39
36
  it "must handle a Tempfile when provided" do
@@ -42,7 +39,7 @@ describe Lager do
42
39
  Foo.log_level = :debug
43
40
  Foo.bar # does debug logging
44
41
  t.rewind
45
- t.read.wont_be_empty
42
+ expect(t.read).wont_be_empty
46
43
  t.close
47
44
  t.unlink
48
45
  end
@@ -53,7 +50,7 @@ describe Lager do
53
50
  Foo.log_level = :debug
54
51
  Foo.bar # does debug logging
55
52
  Foo.log_to $stderr
56
- File.exists?(fname).must_equal true
53
+ expect(File.exist?(fname)).must_equal true
57
54
  File.unlink fname
58
55
  end
59
56
  end
@@ -65,23 +62,25 @@ describe Lager do
65
62
 
66
63
  it "must accept :debug as :debug" do
67
64
  Foo.log_level = :debug
68
- Foo.log_level.must_equal :debug
65
+ expect(Foo.log_level).must_equal :debug
69
66
  end
70
67
 
71
68
  it "must accept Logger::INFO as :info" do
72
69
  Foo.log_level = Logger::INFO
73
- Foo.log_level.must_equal :info
70
+ expect(Foo.log_level).must_equal :info
74
71
  end
75
72
 
76
73
  it "must accept 'warn' as :warn" do
77
74
  Foo.log_level = 'warn'
78
- Foo.log_level.must_equal :warn
75
+ expect(Foo.log_level).must_equal :warn
79
76
  end
80
77
 
81
78
  def must_ignore level
82
79
  lev = Foo.log_level
83
- Foo.log_level = level
84
- Foo.log_level.must_equal lev
80
+ capture_subprocess_io do # suppress warnings
81
+ Foo.log_level = level
82
+ end
83
+ expect(Foo.log_level).must_equal lev
85
84
  end
86
85
 
87
86
  it "must ignore a bad symbol" do
metadata CHANGED
@@ -1,86 +1,48 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2.1
5
- prerelease:
4
+ version: 1.1.4.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Rick Hull
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-10 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: minitest
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: buildar
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: '1.4'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: '1.4'
11
+ date: 1980-01-01 00:00:00.000000000 Z
12
+ dependencies: []
46
13
  description: Should you use it? Yes.
47
- email:
14
+ email:
48
15
  executables: []
49
16
  extensions: []
50
17
  extra_rdoc_files: []
51
18
  files:
52
- - lager.gemspec
53
- - MANIFEST.txt
54
- - VERSION
55
19
  - README.md
56
- - rakefile.rb
20
+ - Rakefile
21
+ - VERSION
22
+ - lager.gemspec
57
23
  - lib/lager.rb
58
24
  - test/lager.rb
59
- - examples/foo.rb
60
- - examples/usage.rb
61
25
  homepage: http://github.com/rickhull/lager
62
26
  licenses:
63
- - LGPL
64
- post_install_message:
27
+ - LGPL-3.0
28
+ metadata: {}
29
+ post_install_message:
65
30
  rdoc_options: []
66
31
  require_paths:
67
32
  - lib
68
33
  required_ruby_version: !ruby/object:Gem::Requirement
69
- none: false
70
34
  requirements:
71
- - - ! '>='
35
+ - - ">"
72
36
  - !ruby/object:Gem::Version
73
- version: '0'
37
+ version: '2'
74
38
  required_rubygems_version: !ruby/object:Gem::Requirement
75
- none: false
76
39
  requirements:
77
- - - ! '>='
40
+ - - ">="
78
41
  - !ruby/object:Gem::Version
79
42
  version: '0'
80
43
  requirements: []
81
- rubyforge_project:
82
- rubygems_version: 1.8.23
83
- signing_key:
84
- specification_version: 3
44
+ rubygems_version: 3.4.4
45
+ signing_key:
46
+ specification_version: 4
85
47
  summary: Sane class-level logging
86
48
  test_files: []
data/MANIFEST.txt DELETED
@@ -1,9 +0,0 @@
1
- lager.gemspec
2
- MANIFEST.txt
3
- VERSION
4
- README.md
5
- rakefile.rb
6
- lib/lager.rb
7
- test/lager.rb
8
- examples/foo.rb
9
- examples/usage.rb
data/examples/foo.rb DELETED
@@ -1,36 +0,0 @@
1
- require_relative '../lib/lager'
2
-
3
- class Foo
4
- extend Lager
5
-
6
- # set logging from within, useful for default behavior
7
- #
8
- log_to $stdout, :warn
9
-
10
- def self.bar
11
- @lager.debug { "inside Foo.bar" }
12
- end
13
-
14
- def initialize
15
- # assign @lager at the instance layer if you want to use it
16
- # @lager, here, is technically a different variable than used above
17
- # though we are setting them to the same thing
18
- #
19
- @lager = self.class.lager
20
- @lager.debug { "inside Foo#initialize" }
21
- end
22
- end
23
-
24
- if __FILE__ == $0
25
- Foo.bar
26
- Foo.new
27
-
28
- # set logging from outside
29
- #
30
- puts "Turning on debug logging"
31
- Foo.log_to $stderr
32
- Foo.log_level :debug
33
-
34
- Foo.bar
35
- Foo.new
36
- end
data/examples/usage.rb DELETED
@@ -1,40 +0,0 @@
1
- require_relative '../lib/lager'
2
-
3
- class Foo
4
- extend Lager
5
- log_to $stdout, :debug # sets up @lager at the class layer
6
-
7
- def self.bar(baz)
8
- unless baz.is_a?(String)
9
- @lager.debug { "baz #{baz} is a #{baz.class}, not a string" }
10
- end
11
- end
12
-
13
- def initialize
14
- # set the instance layer's @lager to the class layer's @lager
15
- @lager = self.class.lager
16
- # now both layers are using the same instance
17
- end
18
-
19
- def do_something_complicated
20
- @lager.debug { "about to do something complicated" }
21
- # ...
22
- @lager.debug { "whew! we made it!" }
23
- end
24
- end
25
-
26
- if __FILE__ == $0
27
- puts "About to spew debug messages"
28
- Foo.bar(15)
29
- f = Foo.new
30
- f.do_something_complicated
31
-
32
- puts "Now updating Foo's log level"
33
- Foo.log_level :warn
34
- Foo.new.do_something_complicated
35
-
36
- puts "Now the same calls as before"
37
- Foo.bar(15)
38
- f = Foo.new
39
- f.do_something_complicated
40
- end
data/rakefile.rb DELETED
@@ -1,14 +0,0 @@
1
- require 'buildar/tasks'
2
- require 'rake/testtask'
3
-
4
- Buildar.conf(__FILE__) do |b|
5
- b.name = 'lager'
6
- b.use_version_file = true
7
- b.version_filename = 'VERSION'
8
- b.use_git = true
9
- b.publish[:rubygems] = true
10
- end
11
-
12
- Rake::TestTask.new :test do |t|
13
- t.pattern = 'test/*.rb'
14
- end