mixlib-log 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +8 -0
- data/NOTICE +12 -11
- data/README.md +51 -0
- data/Rakefile +26 -16
- data/lib/mixlib/log.rb +42 -17
- data/lib/mixlib/log/formatter.rb +11 -11
- data/lib/mixlib/log/version.rb +1 -1
- data/mixlib-log.gemspec +13 -10
- data/spec/mixlib/log/formatter_spec.rb +16 -16
- data/spec/mixlib/log_spec.rb +64 -26
- data/spec/spec_helper.rb +10 -10
- metadata +57 -35
- data/README.rdoc +0 -24
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 544baac7f1e2b650cbc24df38d3de72213a1d0f1
|
4
|
+
data.tar.gz: 8341529d68de0f42bd7abe96632a9fc07479c7d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5e65164468246890adba2b2e4f60a62895a3d97e5e9b838ad553da578657090d9b2f0b8fe86063b1c1bdda7e7bcfc682606960ac5801169f92ac59f45b212eb1
|
7
|
+
data.tar.gz: 1ae4bb47ae23854e030b617ef653e2b45242d247398a0dc1d0d817f4259cfa9c69314ab802707e50400c69eb5465445c40888c4c40093e85a4171d4d3c56b1ff
|
data/Gemfile
ADDED
data/NOTICE
CHANGED
@@ -1,27 +1,28 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
============
|
2
|
+
Mixin::Log Notices
|
3
|
+
============
|
3
4
|
|
4
|
-
Developed at
|
5
|
+
Developed at Chef (http://www.chef.io).
|
5
6
|
|
6
|
-
|
7
|
+
|
8
|
+
* Copyright 2009-2016, Chef Software, Inc. <legal@chef.io>
|
7
9
|
|
8
10
|
Mixin::Log incorporates code from Chef. The Chef notice file follows:
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
+
============
|
13
|
+
Chef Notices
|
14
|
+
============
|
12
15
|
|
13
|
-
Developed at
|
16
|
+
Developed at Chef (http://www.chef.io).
|
14
17
|
|
15
18
|
Contributors and Copyright holders:
|
16
19
|
|
17
|
-
* Copyright 2008, Adam Jacob <adam@
|
20
|
+
* Copyright 2008, Adam Jacob <adam@chef.io>
|
18
21
|
* Copyright 2008, Arjuna Christensen <aj@hjksolutions.com>
|
19
22
|
* Copyright 2008, Bryan McLellan <btm@loftninjas.org>
|
20
23
|
* Copyright 2008, Ezra Zygmuntowicz <ezra@engineyard.com>
|
21
24
|
* Copyright 2009, Sean Cribbs <seancribbs@gmail.com>
|
22
|
-
* Copyright 2009, Christopher Brown <cb@
|
25
|
+
* Copyright 2009, Christopher Brown <cb@chef.io>
|
23
26
|
* Copyright 2009, Thom May <thom@clearairturbulence.org>
|
24
27
|
|
25
28
|
Chef incorporates code modified from Open4 (http://www.codeforpeople.com/lib/ruby/open4/), which was written by Ara T. Howard.
|
26
|
-
|
27
|
-
Chef incorporates code modified from Merb (http://www.merbivore.com), which is Copyright (c) 2008 Engine Yard.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Mixlib::Log
|
2
|
+
|
3
|
+
[![Build Status Master](https://travis-ci.org/chef/mixlib-log.svg?branch=master)](https://travis-ci.org/chef/mixlib-log) [![Gem Version](https://badge.fury.io/rb/mixlib-log.svg)](https://badge.fury.io/rb/mixlib-log)
|
4
|
+
|
5
|
+
Mixlib::Log provides a mixin for enabling a class based logger object, a-la Merb, Chef, and Nanite. To use it:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
require 'mixlib/log'
|
9
|
+
|
10
|
+
class Log
|
11
|
+
extend Mixlib::Log
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
You can then do:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Log.debug('foo')
|
19
|
+
Log.info('bar')
|
20
|
+
Log.warn('baz')
|
21
|
+
Log.error('baz')
|
22
|
+
Log.fatal('wewt')
|
23
|
+
```
|
24
|
+
|
25
|
+
By default, `Mixlib::Logger` logs to STDOUT. To alter this, you should call +Log.init+, passing any arguments to the standard Ruby Logger. For example:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
Log.init('/tmp/logfile') # log to /tmp/logfile
|
29
|
+
Log.init('/tmp/logfile', 7) # log to /tmp/logfile, rotate every day
|
30
|
+
```
|
31
|
+
|
32
|
+
Enjoy!
|
33
|
+
|
34
|
+
## LICENSE:
|
35
|
+
|
36
|
+
- Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
|
37
|
+
- License:: Apache License, Version 2.0
|
38
|
+
|
39
|
+
```text
|
40
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
41
|
+
you may not use this file except in compliance with the License.
|
42
|
+
You may obtain a copy of the License at
|
43
|
+
|
44
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
45
|
+
|
46
|
+
Unless required by applicable law or agreed to in writing, software
|
47
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
48
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
49
|
+
See the License for the specific language governing permissions and
|
50
|
+
limitations under the License.
|
51
|
+
```
|
data/Rakefile
CHANGED
@@ -1,18 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require 'rspec/core/rake_task'
|
6
|
-
require 'cucumber/rake/task'
|
7
|
-
|
8
|
-
gemspec = eval(IO.read('mixlib-log.gemspec'))
|
9
|
-
|
10
|
-
Gem::PackageTask.new(gemspec) do |pkg|
|
11
|
-
pkg.gem_spec = gemspec
|
12
|
-
end
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rdoc/task"
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
require "cucumber/rake/task"
|
13
5
|
|
14
6
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
15
|
-
spec.pattern =
|
7
|
+
spec.pattern = "spec/**/*_spec.rb"
|
16
8
|
end
|
17
9
|
|
18
10
|
task :default => :spec
|
@@ -21,13 +13,31 @@ task :default => :spec
|
|
21
13
|
task :test => :spec
|
22
14
|
|
23
15
|
RDoc::Task.new do |rdoc|
|
24
|
-
rdoc.rdoc_dir =
|
16
|
+
rdoc.rdoc_dir = "rdoc"
|
25
17
|
rdoc.title = "mixlib-log #{Mixlib::Log::VERSION}"
|
26
|
-
rdoc.rdoc_files.include(
|
27
|
-
rdoc.rdoc_files.include(
|
18
|
+
rdoc.rdoc_files.include("README*")
|
19
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
28
20
|
end
|
29
21
|
|
30
22
|
Cucumber::Rake::Task.new(:features) do |t|
|
31
23
|
t.cucumber_opts = "--format pretty"
|
32
24
|
end
|
33
25
|
|
26
|
+
begin
|
27
|
+
require "chefstyle"
|
28
|
+
require "rubocop/rake_task"
|
29
|
+
RuboCop::RakeTask.new(:style) do |task|
|
30
|
+
task.options += ["--display-cop-names", "--no-color"]
|
31
|
+
end
|
32
|
+
rescue LoadError
|
33
|
+
puts "chefstyle/rubocop is not available. gem install chefstyle to do style checking."
|
34
|
+
end
|
35
|
+
|
36
|
+
require "github_changelog_generator/task"
|
37
|
+
|
38
|
+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
39
|
+
config.future_release = Mixlib::Log::VERSION
|
40
|
+
config.enhancement_labels = "enhancement,Enhancement,New Feature,Feature".split(",")
|
41
|
+
config.bug_labels = "bug,Bug,Improvement,Upstream Bug".split(",")
|
42
|
+
config.exclude_labels = "duplicate,question,invalid,wontfix,no_changelog,Exclude From Changelog,Question,Discussion".split(",")
|
43
|
+
end
|
data/lib/mixlib/log.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Adam Jacob (<adam@
|
3
|
-
# Author:: Christopher Brown (<cb@
|
4
|
-
# Copyright:: Copyright (c) 2008
|
2
|
+
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
+
# Author:: Christopher Brown (<cb@chef.io>)
|
4
|
+
# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -16,20 +16,20 @@
|
|
16
16
|
# See the License for the specific language governing permissions and
|
17
17
|
# limitations under the License.
|
18
18
|
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
19
|
+
require "logger"
|
20
|
+
require "mixlib/log/version"
|
21
|
+
require "mixlib/log/formatter"
|
22
22
|
|
23
23
|
module Mixlib
|
24
24
|
module Log
|
25
25
|
|
26
26
|
@logger, @loggers = nil
|
27
27
|
|
28
|
-
LEVELS = { :debug=>Logger::DEBUG, :info=>Logger::INFO, :warn=>Logger::WARN, :error=>Logger::ERROR, :fatal=>Logger::FATAL}.freeze
|
28
|
+
LEVELS = { :debug => Logger::DEBUG, :info => Logger::INFO, :warn => Logger::WARN, :error => Logger::ERROR, :fatal => Logger::FATAL }.freeze
|
29
29
|
LEVEL_NAMES = LEVELS.invert.freeze
|
30
30
|
|
31
|
-
|
32
31
|
def reset!
|
32
|
+
close!
|
33
33
|
@logger, @loggers = nil, nil
|
34
34
|
end
|
35
35
|
|
@@ -51,7 +51,7 @@ module Mixlib
|
|
51
51
|
# that had been added to the +loggers+ array will be cleared.
|
52
52
|
def logger=(new_log_device)
|
53
53
|
reset!
|
54
|
-
@logger=new_log_device
|
54
|
+
@logger = new_log_device
|
55
55
|
end
|
56
56
|
|
57
57
|
def use_log_devices(other)
|
@@ -63,7 +63,7 @@ module Mixlib
|
|
63
63
|
@logger = other.first
|
64
64
|
else
|
65
65
|
msg = "#use_log_devices takes a Mixlib::Log object or array of log devices. " <<
|
66
|
-
|
66
|
+
"You gave: #{other.inspect}"
|
67
67
|
raise ArgumentError, msg
|
68
68
|
end
|
69
69
|
end
|
@@ -95,14 +95,14 @@ module Mixlib
|
|
95
95
|
def level=(new_level)
|
96
96
|
level_int = LEVEL_NAMES.key?(new_level) ? new_level : LEVELS[new_level]
|
97
97
|
raise ArgumentError, "Log level must be one of :debug, :info, :warn, :error, or :fatal" if level_int.nil?
|
98
|
-
loggers.each {|l| l.level = level_int }
|
98
|
+
loggers.each { |l| l.level = level_int }
|
99
99
|
end
|
100
100
|
|
101
|
-
def level(new_level=nil)
|
101
|
+
def level(new_level = nil)
|
102
102
|
if new_level.nil?
|
103
103
|
LEVEL_NAMES[logger.level]
|
104
104
|
else
|
105
|
-
self.level=(new_level)
|
105
|
+
self.level = (new_level)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
@@ -129,11 +129,11 @@ module Mixlib
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def <<(msg)
|
132
|
-
loggers.each {|l| l << msg }
|
132
|
+
loggers.each { |l| l << msg }
|
133
133
|
end
|
134
134
|
|
135
135
|
def add(severity, message = nil, progname = nil, &block)
|
136
|
-
loggers.each {|l| l.add(severity, message
|
136
|
+
loggers.each { |l| l.add(severity, message, progname, &block) }
|
137
137
|
end
|
138
138
|
|
139
139
|
alias :log :add
|
@@ -142,7 +142,7 @@ module Mixlib
|
|
142
142
|
# this method gets hit before a call to Mixlib::Logger.init has been made, it will call
|
143
143
|
# Mixlib::Logger.init() with no arguments.
|
144
144
|
def method_missing(method_symbol, *args, &block)
|
145
|
-
loggers.each {|l| l.send(method_symbol, *args, &block) }
|
145
|
+
loggers.each { |l| l.send(method_symbol, *args, &block) }
|
146
146
|
end
|
147
147
|
|
148
148
|
private
|
@@ -150,12 +150,37 @@ module Mixlib
|
|
150
150
|
def logger_for(*opts)
|
151
151
|
if opts.empty?
|
152
152
|
Logger.new(STDOUT)
|
153
|
-
elsif LEVELS.keys.inject(true) {|quacks, level| quacks && opts.first.respond_to?(level)}
|
153
|
+
elsif LEVELS.keys.inject(true) { |quacks, level| quacks && opts.first.respond_to?(level) }
|
154
154
|
opts.first
|
155
155
|
else
|
156
156
|
Logger.new(*opts)
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
160
|
+
def all_loggers
|
161
|
+
[@logger, *@loggers].uniq
|
162
|
+
end
|
163
|
+
|
164
|
+
# select all loggers with File log devices
|
165
|
+
def loggers_to_close
|
166
|
+
loggers_to_close = []
|
167
|
+
all_loggers.each do |logger|
|
168
|
+
# unfortunately Logger does not provide access to the logdev
|
169
|
+
# via public API. In order to reduce amount of impact and
|
170
|
+
# handle only File type log devices I had to use this method
|
171
|
+
# to get access to it.
|
172
|
+
next unless logdev = logger.instance_variable_get(:"@logdev")
|
173
|
+
loggers_to_close << logger if logdev.filename
|
174
|
+
end
|
175
|
+
loggers_to_close
|
176
|
+
end
|
177
|
+
|
178
|
+
def close!
|
179
|
+
# try to close all file loggers
|
180
|
+
loggers_to_close.each do |l|
|
181
|
+
l.close rescue nil
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
160
185
|
end
|
161
186
|
end
|
data/lib/mixlib/log/formatter.rb
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Adam Jacob (<adam@
|
3
|
-
# Copyright:: Copyright (c) 2008
|
2
|
+
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
8
8
|
# You may obtain a copy of the License at
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Unless required by applicable law or agreed to in writing, software
|
13
13
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
14
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
|
18
|
-
require
|
19
|
-
require
|
18
|
+
require "logger"
|
19
|
+
require "time"
|
20
20
|
|
21
21
|
module Mixlib
|
22
22
|
module Log
|
23
23
|
class Formatter < Logger::Formatter
|
24
24
|
@@show_time = true
|
25
|
-
|
26
|
-
def self.show_time=(show=false)
|
25
|
+
|
26
|
+
def self.show_time=(show = false)
|
27
27
|
@@show_time = show
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
# Prints a log message as '[time] severity: message' if Chef::Log::Formatter.show_time == true.
|
31
31
|
# Otherwise, doesn't print the time.
|
32
32
|
def call(severity, time, progname, msg)
|
@@ -36,9 +36,9 @@ module Mixlib
|
|
36
36
|
sprintf("%s: %s\n", severity, msg2str(msg))
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
# Converts some argument to a Logger.severity() call to a string. Regular strings pass through like
|
41
|
-
# normal, Exceptions get formatted as "message (class)\nbacktrace", and other random stuff gets
|
41
|
+
# normal, Exceptions get formatted as "message (class)\nbacktrace", and other random stuff gets
|
42
42
|
# put through "object.inspect"
|
43
43
|
def msg2str(msg)
|
44
44
|
case msg
|
data/lib/mixlib/log/version.rb
CHANGED
data/mixlib-log.gemspec
CHANGED
@@ -1,18 +1,21 @@
|
|
1
|
-
$:.unshift File.expand_path(
|
2
|
-
require
|
1
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
require "mixlib/log/version"
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.name = "mixlib-log"
|
6
6
|
gem.version = Mixlib::Log::VERSION
|
7
7
|
gem.platform = Gem::Platform::RUBY
|
8
8
|
gem.summary = "A gem that provides a simple mixin for log functionality"
|
9
|
-
gem.email = "info@
|
10
|
-
gem.homepage = "
|
11
|
-
gem.
|
9
|
+
gem.email = "info@chef.io"
|
10
|
+
gem.homepage = "https://www.chef.io"
|
11
|
+
gem.license = "Apache-2.0"
|
12
|
+
gem.authors = ["Chef Software, Inc."]
|
12
13
|
gem.has_rdoc = true
|
13
|
-
gem.extra_rdoc_files = ["README.
|
14
|
-
gem.files = Dir[
|
15
|
-
gem.add_development_dependency
|
16
|
-
gem.add_development_dependency
|
17
|
-
gem.add_development_dependency
|
14
|
+
gem.extra_rdoc_files = ["README.md", "LICENSE", "NOTICE"]
|
15
|
+
gem.files = Dir["lib/**/*"] + Dir["spec/**/*"] + ["Gemfile", "Rakefile", ".gemtest", "mixlib-log.gemspec"]
|
16
|
+
gem.add_development_dependency "rake"
|
17
|
+
gem.add_development_dependency "rspec", "~> 3.4"
|
18
|
+
gem.add_development_dependency "chefstyle", "~> 0.3"
|
19
|
+
gem.add_development_dependency "cucumber"
|
20
|
+
gem.add_development_dependency "github_changelog_generator", "1.11.3"
|
18
21
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Adam Jacob (<adam@
|
3
|
-
# Copyright:: Copyright (c) 2008
|
2
|
+
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
8
8
|
# You may obtain a copy of the License at
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Unless required by applicable law or agreed to in writing, software
|
13
13
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
14
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -16,36 +16,36 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
require
|
19
|
+
require "time"
|
20
20
|
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
|
21
21
|
|
22
22
|
describe Mixlib::Log::Formatter do
|
23
23
|
before(:each) do
|
24
24
|
@formatter = Mixlib::Log::Formatter.new
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
it "should print raw strings with msg2str(string)" do
|
28
|
-
@formatter.msg2str("nuthin new").
|
28
|
+
expect(@formatter.msg2str("nuthin new")).to eq("nuthin new")
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
it "should format exceptions properly with msg2str(e)" do
|
32
32
|
e = IOError.new("legendary roots crew")
|
33
|
-
@formatter.msg2str(e).
|
33
|
+
expect(@formatter.msg2str(e)).to eq("legendary roots crew (IOError)\n")
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "should format random objects via inspect with msg2str(Object)" do
|
37
|
-
@formatter.msg2str([ "black thought", "?uestlove" ]).
|
37
|
+
expect(@formatter.msg2str([ "black thought", "?uestlove" ])).to eq('["black thought", "?uestlove"]')
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
it "should return a formatted string with call" do
|
41
41
|
time = Time.new
|
42
42
|
Mixlib::Log::Formatter.show_time = true
|
43
|
-
@formatter.call("monkey", time, "test", "mos def").
|
43
|
+
expect(@formatter.call("monkey", time, "test", "mos def")).to eq("[#{time.iso8601}] monkey: mos def\n")
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it "should allow you to turn the time on and off in the output" do
|
47
47
|
Mixlib::Log::Formatter.show_time = false
|
48
|
-
@formatter.call("monkey", Time.new, "test", "mos def").
|
48
|
+
expect(@formatter.call("monkey", Time.new, "test", "mos def")).to eq("monkey: mos def\n")
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
end
|
data/spec/mixlib/log_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Adam Jacob (<adam@
|
3
|
-
# Author:: Christopher Brown (<cb@
|
4
|
-
# Copyright:: Copyright (c) 2008
|
2
|
+
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
+
# Author:: Christopher Brown (<cb@chef.io>)
|
4
|
+
# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -17,8 +17,8 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
21
|
-
require
|
20
|
+
require "tempfile"
|
21
|
+
require "stringio"
|
22
22
|
require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
|
23
23
|
|
24
24
|
class LoggerLike
|
@@ -49,7 +49,7 @@ describe Mixlib::Log do
|
|
49
49
|
io = StringIO.new
|
50
50
|
Logit.init(io)
|
51
51
|
Logit << "foo"
|
52
|
-
io.string.
|
52
|
+
expect(io.string).to match(/foo/)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "creates a logger with a file name" do
|
@@ -57,7 +57,7 @@ describe Mixlib::Log do
|
|
57
57
|
Logit.init(tempfile.path)
|
58
58
|
Logit << "bar"
|
59
59
|
tempfile.rewind
|
60
|
-
tempfile.read.
|
60
|
+
expect(tempfile.read).to match(/bar/)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -65,18 +65,18 @@ describe Mixlib::Log do
|
|
65
65
|
logger = LoggerLike.new
|
66
66
|
Logit.init(logger)
|
67
67
|
Logit.debug "qux"
|
68
|
-
logger.messages.
|
68
|
+
expect(logger.messages).to match(/qux/)
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should re-initialize the logger if init is called again" do
|
72
72
|
first_logdev, second_logdev = StringIO.new, StringIO.new
|
73
73
|
Logit.init(first_logdev)
|
74
74
|
Logit.fatal "FIRST"
|
75
|
-
first_logdev.string.
|
75
|
+
expect(first_logdev.string).to match(/FIRST/)
|
76
76
|
Logit.init(second_logdev)
|
77
77
|
Logit.fatal "SECOND"
|
78
|
-
first_logdev.string.
|
79
|
-
second_logdev.string.
|
78
|
+
expect(first_logdev.string).to_not match(/SECOND/)
|
79
|
+
expect(second_logdev.string).to match(/SECOND/)
|
80
80
|
end
|
81
81
|
|
82
82
|
it "should set the log level using the binding form, with :debug, :info, :warn, :error, or :fatal" do
|
@@ -85,12 +85,12 @@ describe Mixlib::Log do
|
|
85
85
|
:info => Logger::INFO,
|
86
86
|
:warn => Logger::WARN,
|
87
87
|
:error => Logger::ERROR,
|
88
|
-
:fatal => Logger::FATAL
|
88
|
+
:fatal => Logger::FATAL,
|
89
89
|
}
|
90
90
|
levels.each do |symbol, constant|
|
91
91
|
Logit.level = symbol
|
92
|
-
Logit.logger.level.
|
93
|
-
Logit.level.
|
92
|
+
expect(Logit.logger.level).to eq(constant)
|
93
|
+
expect(Logit.level).to eq(symbol)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -98,50 +98,88 @@ describe Mixlib::Log do
|
|
98
98
|
logdev = StringIO.new
|
99
99
|
Logit.init(logdev)
|
100
100
|
Logit.fatal { "the_message" }
|
101
|
-
logdev.string.
|
101
|
+
expect(logdev.string).to match(/the_message/)
|
102
102
|
end
|
103
103
|
|
104
|
-
|
105
104
|
it "should set the log level using the method form, with :debug, :info, :warn, :error, or :fatal" do
|
106
105
|
levels = {
|
107
106
|
:debug => Logger::DEBUG,
|
108
107
|
:info => Logger::INFO,
|
109
108
|
:warn => Logger::WARN,
|
110
109
|
:error => Logger::ERROR,
|
111
|
-
:fatal => Logger::FATAL
|
110
|
+
:fatal => Logger::FATAL,
|
112
111
|
}
|
113
112
|
levels.each do |symbol, constant|
|
114
113
|
Logit.level(symbol)
|
115
|
-
Logit.logger.level.
|
114
|
+
expect(Logit.logger.level).to eq(constant)
|
116
115
|
end
|
117
116
|
end
|
118
117
|
|
119
118
|
it "should raise an ArgumentError if you try and set the level to something strange using the binding form" do
|
120
|
-
lambda { Logit.level = :the_roots }.
|
119
|
+
expect(lambda { Logit.level = :the_roots }).to raise_error(ArgumentError)
|
121
120
|
end
|
122
121
|
|
123
122
|
it "should raise an ArgumentError if you try and set the level to something strange using the method form" do
|
124
|
-
lambda { Logit.level(:the_roots) }.
|
123
|
+
expect(lambda { Logit.level(:the_roots) }).to raise_error(ArgumentError)
|
125
124
|
end
|
126
125
|
|
127
126
|
it "should pass other method calls directly to logger" do
|
128
127
|
Logit.level = :debug
|
129
|
-
Logit.
|
130
|
-
lambda { Logit.debug("Gimme some sugar!") }.
|
128
|
+
expect(Logit).to be_debug
|
129
|
+
expect(lambda { Logit.debug("Gimme some sugar!") }).to_not raise_error
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should pass add method calls directly to logger" do
|
133
|
+
logdev = StringIO.new
|
134
|
+
Logit.init(logdev)
|
135
|
+
Logit.level = :debug
|
136
|
+
expect(Logit).to be_debug
|
137
|
+
expect(lambda { Logit.add(Logger::DEBUG, "Gimme some sugar!") }).to_not raise_error
|
138
|
+
expect(logdev.string).to match(/Gimme some sugar/)
|
131
139
|
end
|
132
140
|
|
133
141
|
it "should default to STDOUT if init is called with no arguments" do
|
134
142
|
logger_mock = Struct.new(:formatter, :level).new
|
135
|
-
Logger.
|
136
|
-
Logger.should_receive(:new).with(STDOUT).and_return(logger_mock)
|
143
|
+
expect(Logger).to receive(:new).with(STDOUT).and_return(logger_mock)
|
137
144
|
Logit.init
|
138
145
|
end
|
139
146
|
|
140
147
|
it "should have by default a base log level of warn" do
|
141
148
|
logger_mock = Struct.new(:formatter, :level).new
|
142
|
-
Logger.
|
149
|
+
expect(Logger).to receive(:new).and_return(logger_mock)
|
143
150
|
Logit.init
|
144
|
-
Logit.level.
|
151
|
+
expect(Logit.level).to eq(:warn)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should close File logger" do
|
155
|
+
opened_files_count_before = 0
|
156
|
+
ObjectSpace.each_object(File) do |f|
|
157
|
+
opened_files_count_before += 1 unless f.closed?
|
158
|
+
end
|
159
|
+
Logit.init("/tmp/logger.log")
|
160
|
+
Logit.init("/tmp/logger.log")
|
161
|
+
Logit.init("/tmp/logger.log")
|
162
|
+
opened_files_count_after = 0
|
163
|
+
ObjectSpace.each_object(File) do |f|
|
164
|
+
opened_files_count_after += 1 unless f.closed?
|
165
|
+
end
|
166
|
+
expect(opened_files_count_after).to eq(opened_files_count_before + 1)
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should not close IO logger" do
|
170
|
+
opened_files_count_before = 0
|
171
|
+
ObjectSpace.each_object(File) do |f|
|
172
|
+
opened_files_count_before += 1 unless f.closed?
|
173
|
+
end
|
174
|
+
file = File.open("/tmp/logger.log")
|
175
|
+
Logit.init(file)
|
176
|
+
Logit.init(file)
|
177
|
+
Logit.init(file)
|
178
|
+
opened_files_count_after = 0
|
179
|
+
ObjectSpace.each_object(File) do |f|
|
180
|
+
opened_files_count_after += 1 unless f.closed?
|
181
|
+
end
|
182
|
+
expect(opened_files_count_after).to eq(opened_files_count_before + 1)
|
145
183
|
end
|
146
184
|
|
147
185
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
#
|
2
|
-
# Author:: Adam Jacob (<adam@
|
3
|
-
# Author:: Christopher Brown (<cb@
|
4
|
-
# Copyright:: Copyright (c) 2008
|
2
|
+
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
+
# Author:: Christopher Brown (<cb@chef.io>)
|
4
|
+
# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc..
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
# you may not use this file except in compliance with the License.
|
9
9
|
# You may obtain a copy of the License at
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# Unless required by applicable law or agreed to in writing, software
|
14
14
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
15
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -17,12 +17,12 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
$TESTING=true
|
21
|
-
$:.push File.join(File.dirname(__FILE__),
|
20
|
+
$TESTING = true
|
21
|
+
$:.push File.join(File.dirname(__FILE__), "..", "lib")
|
22
22
|
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
23
|
+
require "rspec"
|
24
|
+
require "mixlib/log"
|
25
|
+
require "mixlib/log/formatter"
|
26
26
|
|
27
27
|
class Logit
|
28
28
|
extend Mixlib::Log
|
metadata
CHANGED
@@ -1,107 +1,129 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mixlib-log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.7.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
|
-
-
|
7
|
+
- Chef Software, Inc.
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-08-04 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
33
|
+
version: '3.4'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
40
|
+
version: '3.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: chefstyle
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.3'
|
46
55
|
- !ruby/object:Gem::Dependency
|
47
56
|
name: cucumber
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
58
|
requirements:
|
51
|
-
- -
|
59
|
+
- - ">="
|
52
60
|
- !ruby/object:Gem::Version
|
53
61
|
version: '0'
|
54
62
|
type: :development
|
55
63
|
prerelease: false
|
56
64
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
65
|
requirements:
|
59
|
-
- -
|
66
|
+
- - ">="
|
60
67
|
- !ruby/object:Gem::Version
|
61
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: github_changelog_generator
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.11.3
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.11.3
|
62
83
|
description:
|
63
|
-
email: info@
|
84
|
+
email: info@chef.io
|
64
85
|
executables: []
|
65
86
|
extensions: []
|
66
87
|
extra_rdoc_files:
|
67
|
-
- README.
|
88
|
+
- README.md
|
68
89
|
- LICENSE
|
69
90
|
- NOTICE
|
70
91
|
files:
|
92
|
+
- ".gemtest"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE
|
95
|
+
- NOTICE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- lib/mixlib/log.rb
|
71
99
|
- lib/mixlib/log/formatter.rb
|
72
100
|
- lib/mixlib/log/version.rb
|
73
|
-
-
|
101
|
+
- mixlib-log.gemspec
|
74
102
|
- spec/mixlib/log/formatter_spec.rb
|
75
103
|
- spec/mixlib/log_spec.rb
|
76
104
|
- spec/spec_helper.rb
|
77
|
-
|
78
|
-
|
79
|
-
-
|
80
|
-
|
81
|
-
- LICENSE
|
82
|
-
- NOTICE
|
83
|
-
homepage: http://www.opscode.com
|
84
|
-
licenses: []
|
105
|
+
homepage: https://www.chef.io
|
106
|
+
licenses:
|
107
|
+
- Apache-2.0
|
108
|
+
metadata: {}
|
85
109
|
post_install_message:
|
86
110
|
rdoc_options: []
|
87
111
|
require_paths:
|
88
112
|
- lib
|
89
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
114
|
requirements:
|
92
|
-
- -
|
115
|
+
- - ">="
|
93
116
|
- !ruby/object:Gem::Version
|
94
117
|
version: '0'
|
95
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
-
none: false
|
97
119
|
requirements:
|
98
|
-
- -
|
120
|
+
- - ">="
|
99
121
|
- !ruby/object:Gem::Version
|
100
122
|
version: '0'
|
101
123
|
requirements: []
|
102
124
|
rubyforge_project:
|
103
|
-
rubygems_version:
|
125
|
+
rubygems_version: 2.4.5.1
|
104
126
|
signing_key:
|
105
|
-
specification_version:
|
127
|
+
specification_version: 4
|
106
128
|
summary: A gem that provides a simple mixin for log functionality
|
107
129
|
test_files: []
|
data/README.rdoc
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
== Mixlib::Log
|
2
|
-
|
3
|
-
Mixlib::Log provides a mixin for enabling a class based logger object, a-la Merb, Chef, and Nanite. To use it:
|
4
|
-
|
5
|
-
require 'mixlib/log'
|
6
|
-
|
7
|
-
class Log
|
8
|
-
extend Mixlib::Log
|
9
|
-
end
|
10
|
-
|
11
|
-
You can then do:
|
12
|
-
|
13
|
-
Log.debug("foo")
|
14
|
-
Log.info("bar")
|
15
|
-
Log.warn("baz")
|
16
|
-
Log.error("baz")
|
17
|
-
Log.fatal("wewt")
|
18
|
-
|
19
|
-
By default, Mixlib::Logger logs to STDOUT. To alter this, you should call Log.init, passing any arguments to the standard Ruby Logger. For example:
|
20
|
-
|
21
|
-
Log.init("/tmp/logfile") # log to /tmp/logfile
|
22
|
-
Log.init("/tmp/logfile", 7) # log to /tmp/logfile, rotate every day
|
23
|
-
|
24
|
-
Enjoy!
|