lager 1.1.3.1 → 1.1.4.1

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: 64b64cc70e40a568fafd57dd3734138c27f60110
4
- data.tar.gz: a3a04e2ccd0fbd5e3353b4d6bb8319c1fe3bec09
2
+ SHA256:
3
+ metadata.gz: ddc68c3afe5aa76a06167a875a6023bd06c2b4c9092f9ca2190cfad926ba7142
4
+ data.tar.gz: 7df85fefabc6f5bd0618d5c0b9a5c0005321ab7011e30648155463eaf8fafabd
5
5
  SHA512:
6
- metadata.gz: 0867774d99d08023b09b4c823d41939197f9b74b12e3ee585e0d809aae12dc143172bb8a6b68d9d0590ec905a993e3a73b847e3fa7dee9983bf3017f30fa12fe
7
- data.tar.gz: 0346d4b317fe7914666fb35fa4676b97600bd82509c92fedab6b48e1191d7def7401cf01153a41144022efa6c641b1dfeb86f6bdd95362a004b5254137f2791f
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
 
@@ -87,17 +105,21 @@ For Logger, generally: use block invocation of message methods.
87
105
  @lager.debug "hi"
88
106
  ```
89
107
 
90
- By using the first form, the block will not be evaluated unless you are logging at DEBUG level. If using the second form, the message is evaluated no matter the current log level. This can be significant when logging heavily processed messages.
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.
91
112
 
92
113
  Artifacts
93
114
  ---------
94
- * By mixing in Lager via extend, you introduce these class methods:
115
+ * By mixing in via `extend Lager`, you introduce these class methods:
95
116
  * lager
96
117
  * log_to
97
118
  * log_level
98
119
  * log_level=
99
- * By calling log_to, you introduce the *class instance variable* @lager
100
- * 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`
101
123
 
102
124
  Now you have a unified interface for logging at both class and instance layers.
103
125
 
@@ -107,7 +129,8 @@ Now you have a unified interface for logging at both class and instance layers.
107
129
 
108
130
  Use an existing Logger instance
109
131
  -------------------------------
110
- 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:
111
134
 
112
135
  ```ruby
113
136
  class Foo
@@ -117,7 +140,8 @@ class Foo
117
140
  end
118
141
  ```
119
142
 
120
- 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:
121
145
 
122
146
  ```ruby
123
147
  class Foo
@@ -134,6 +158,7 @@ Foo.log_to Project.log
134
158
 
135
159
  Inheritance
136
160
  -----------
161
+
137
162
  ```ruby
138
163
  class Foo
139
164
  extend Lager
data/Rakefile CHANGED
@@ -1,12 +1,21 @@
1
- require 'buildar'
2
1
  require 'rake/testtask'
3
2
 
4
- Buildar.new do |b|
5
- b.gemspec_file = 'lager.gemspec'
6
- b.version_file = 'VERSION'
7
- b.use_git = true
8
- end
9
-
3
+ desc "Run tests"
10
4
  Rake::TestTask.new :test do |t|
11
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"
12
21
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.3.1
1
+ 1.1.4.1
data/lager.gemspec CHANGED
@@ -1,28 +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", ["~> 1"]
11
- s.add_development_dependency "buildar", ["~> 1"]
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')
11
+ s.version = File.read(File.join(__dir__, 'VERSION')).chomp
16
12
 
17
13
  # dynamic assignments
18
- s.version = File.read(version_file).chomp
19
- s.files = %w[lager.gemspec
20
- VERSION
21
- README.md
22
- Rakefile
23
- lib/lager.rb
24
- test/lager.rb
25
- examples/foo.rb
26
- examples/usage.rb
27
- ]
14
+ s.files = %w[lager.gemspec VERSION README.md Rakefile]
15
+ s.files += Dir['lib/**/*.rb']
16
+ s.files += Dir['test/**/*.rb']
28
17
  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
23
  it "must return its argument" do
27
- Foo.log_to($stdout).must_equal $stdout
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,45 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3.1
4
+ version: 1.1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Hull
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-30 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: minitest
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1'
27
- - !ruby/object:Gem::Dependency
28
- name: buildar
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1'
11
+ date: 1980-01-01 00:00:00.000000000 Z
12
+ dependencies: []
41
13
  description: Should you use it? Yes.
42
- email:
14
+ email:
43
15
  executables: []
44
16
  extensions: []
45
17
  extra_rdoc_files: []
@@ -47,33 +19,30 @@ files:
47
19
  - README.md
48
20
  - Rakefile
49
21
  - VERSION
50
- - examples/foo.rb
51
- - examples/usage.rb
52
22
  - lager.gemspec
53
23
  - lib/lager.rb
54
24
  - test/lager.rb
55
25
  homepage: http://github.com/rickhull/lager
56
26
  licenses:
57
- - LGPL
27
+ - LGPL-3.0
58
28
  metadata: {}
59
- post_install_message:
29
+ post_install_message:
60
30
  rdoc_options: []
61
31
  require_paths:
62
32
  - lib
63
33
  required_ruby_version: !ruby/object:Gem::Requirement
64
34
  requirements:
65
- - - ">="
35
+ - - ">"
66
36
  - !ruby/object:Gem::Version
67
- version: '0'
37
+ version: '2'
68
38
  required_rubygems_version: !ruby/object:Gem::Requirement
69
39
  requirements:
70
40
  - - ">="
71
41
  - !ruby/object:Gem::Version
72
42
  version: '0'
73
43
  requirements: []
74
- rubyforge_project:
75
- rubygems_version: 2.2.2
76
- signing_key:
44
+ rubygems_version: 3.4.4
45
+ signing_key:
77
46
  specification_version: 4
78
47
  summary: Sane class-level logging
79
48
  test_files: []
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