mixlib-log 2.0.4 → 2.0.9

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
  SHA256:
3
- metadata.gz: 9f38162b462a52fdf0dd4465f19065171321ac07e34a5a65f9ab577f77b22dcf
4
- data.tar.gz: dafa77b839b7ea7f94ee5614d29a054756d2d0115100fa7f3b44f2afcb23624a
3
+ metadata.gz: a4360d5e8145d44c3bb5924bb02c741095094cc716139620f09d3efe8780a3a8
4
+ data.tar.gz: b4799ecbf00988179849a92fb8692e018fd062905c3dbb75a82181ecaefc7568
5
5
  SHA512:
6
- metadata.gz: e4b4141f0fcbe6f14ac1ff949f7771179cb617af4fc0f7d1f934d7e3db67e70dfd9dc443886f64ceda4a1531b946c945567bea69e82405cef3ea746bb28bf9ff
7
- data.tar.gz: 6c2a02ccc1d4967241d5a4439562cff07ef0620c750ee29809ecb172c81a24e7b7b746ebcc4da8fdf6a3f2f1d89210f7cc3fee5efbe96eac460aa082c720ecdf
6
+ metadata.gz: 39b7e45f04d2777ff7024f6c77746763eb52fc79d996a0198cf8ef04c1a6cef5b7d813322f4b799f92fe6bf958280e1d84efa1a572f81c0136c1deefffbba0a6
7
+ data.tar.gz: ab05f0d55208b81abe16d6e25554133af5b2312a6865855dfef90289ed656409d91734db25bc770dbcd6876941ca47a141284d5cd26f62f639f401078143c6fd
@@ -29,7 +29,7 @@ module Mixlib
29
29
  SEV_LABEL[sev + 1] || -"ANY"
30
30
  end
31
31
 
32
- LEVELS = { :trace => TRACE, :debug => DEBUG, :info => INFO, :warn => WARN, :error => ERROR, :fatal => FATAL }.freeze
32
+ LEVELS = { trace: TRACE, debug: DEBUG, info: INFO, warn: WARN, error: ERROR, fatal: FATAL }.freeze
33
33
  LEVEL_NAMES = LEVELS.invert.freeze
34
34
 
35
35
  attr_accessor :metadata
@@ -1,5 +1,5 @@
1
1
  module Mixlib
2
2
  module Log
3
- VERSION = "2.0.4"
3
+ VERSION = "2.0.9".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,112 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixlib-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-12 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '3.7'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '3.7'
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'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: cucumber
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
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
11
+ date: 2018-12-18 00:00:00.000000000 Z
12
+ dependencies: []
83
13
  description:
84
14
  email: info@chef.io
85
15
  executables: []
86
16
  extensions: []
87
- extra_rdoc_files:
88
- - README.md
89
- - LICENSE
90
- - NOTICE
17
+ extra_rdoc_files: []
91
18
  files:
92
- - ".gemtest"
93
- - Gemfile
94
19
  - LICENSE
95
- - NOTICE
96
- - README.md
97
- - Rakefile
98
20
  - lib/mixlib/log.rb
99
21
  - lib/mixlib/log/child.rb
100
22
  - lib/mixlib/log/formatter.rb
101
23
  - lib/mixlib/log/logger.rb
102
24
  - lib/mixlib/log/logging.rb
103
25
  - lib/mixlib/log/version.rb
104
- - mixlib-log.gemspec
105
- - spec/mixlib/log/child_spec.rb
106
- - spec/mixlib/log/formatter_spec.rb
107
- - spec/mixlib/log_spec.rb
108
- - spec/spec_helper.rb
109
- homepage: https://www.chef.io
26
+ homepage: https://github.com/chef/mixlib-log
110
27
  licenses:
111
28
  - Apache-2.0
112
29
  metadata: {}
data/.gemtest DELETED
File without changes
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- group :development do
6
- gem "rdoc"
7
- gem "bundler"
8
- end
data/NOTICE DELETED
@@ -1,28 +0,0 @@
1
- ============
2
- Mixin::Log Notices
3
- ============
4
-
5
- Developed at Chef (http://www.chef.io).
6
-
7
-
8
- * Copyright 2009-2016, Chef Software, Inc. <legal@chef.io>
9
-
10
- Mixin::Log incorporates code from Chef. The Chef notice file follows:
11
-
12
- ============
13
- Chef Notices
14
- ============
15
-
16
- Developed at Chef (http://www.chef.io).
17
-
18
- Contributors and Copyright holders:
19
-
20
- * Copyright 2008, Adam Jacob <adam@chef.io>
21
- * Copyright 2008, Arjuna Christensen <aj@hjksolutions.com>
22
- * Copyright 2008, Bryan McLellan <btm@loftninjas.org>
23
- * Copyright 2008, Ezra Zygmuntowicz <ezra@engineyard.com>
24
- * Copyright 2009, Sean Cribbs <seancribbs@gmail.com>
25
- * Copyright 2009, Christopher Brown <cb@chef.io>
26
- * Copyright 2009, Thom May <thom@clearairturbulence.org>
27
-
28
- Chef incorporates code modified from Open4 (http://www.codeforpeople.com/lib/ruby/open4/), which was written by Ara T. Howard.
data/README.md DELETED
@@ -1,55 +0,0 @@
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
- ## Contributing
35
-
36
- For information on contributing to this project see <https://github.com/chef/chef/blob/master/CONTRIBUTING.md>
37
-
38
- ## License
39
-
40
- - Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
41
- - License:: Apache License, Version 2.0
42
-
43
- ```text
44
- Licensed under the Apache License, Version 2.0 (the "License");
45
- you may not use this file except in compliance with the License.
46
- You may obtain a copy of the License at
47
-
48
- http://www.apache.org/licenses/LICENSE-2.0
49
-
50
- Unless required by applicable law or agreed to in writing, software
51
- distributed under the License is distributed on an "AS IS" BASIS,
52
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
53
- See the License for the specific language governing permissions and
54
- limitations under the License.
55
- ```
data/Rakefile DELETED
@@ -1,43 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rdoc/task"
3
- require "rspec/core/rake_task"
4
- require "cucumber/rake/task"
5
-
6
- RSpec::Core::RakeTask.new(:spec) do |spec|
7
- spec.pattern = "spec/**/*_spec.rb"
8
- end
9
-
10
- task default: [:style, :spec, :features]
11
-
12
- # For rubygems-test
13
- task :test => :spec
14
-
15
- RDoc::Task.new do |rdoc|
16
- rdoc.rdoc_dir = "rdoc"
17
- rdoc.title = "mixlib-log #{Mixlib::Log::VERSION}"
18
- rdoc.rdoc_files.include("README*")
19
- rdoc.rdoc_files.include("lib/**/*.rb")
20
- end
21
-
22
- Cucumber::Rake::Task.new(:features) do |t|
23
- t.cucumber_opts = "--format pretty"
24
- end
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
@@ -1,22 +0,0 @@
1
- $:.unshift File.expand_path("../lib", __FILE__)
2
- require "mixlib/log/version"
3
-
4
- Gem::Specification.new do |gem|
5
- gem.name = "mixlib-log"
6
- gem.version = Mixlib::Log::VERSION
7
- gem.platform = Gem::Platform::RUBY
8
- gem.summary = "A gem that provides a simple mixin for log functionality"
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."]
13
- gem.has_rdoc = true
14
- gem.extra_rdoc_files = ["README.md", "LICENSE", "NOTICE"]
15
- gem.files = Dir["lib/**/*"] + Dir["spec/**/*"] + ["Gemfile", "Rakefile", ".gemtest", "mixlib-log.gemspec"]
16
- gem.required_ruby_version = ">= 2.2"
17
- gem.add_development_dependency "rake"
18
- gem.add_development_dependency "rspec", "~> 3.7"
19
- gem.add_development_dependency "chefstyle"
20
- gem.add_development_dependency "cucumber"
21
- gem.add_development_dependency "github_changelog_generator", ">= 1.11.3"
22
- end
@@ -1,99 +0,0 @@
1
- #
2
- # Copyright:: Copyright (c) 2018 Chef Software, Inc.
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
- require "tempfile"
19
- require "stringio"
20
- require "spec_helper"
21
-
22
- RSpec.describe Mixlib::Log::Child do
23
- before do
24
- Logit.reset!
25
- Logit.init(io)
26
- Logit.level = :warn
27
- end
28
-
29
- let(:io) { StringIO.new }
30
-
31
- let(:child) { Logit.with_child }
32
-
33
- it "has a parent" do
34
- expect(child.parent).to be(Logit)
35
- end
36
-
37
- it "accepts a message" do
38
- Logit.with_child { |l| l.add(Logger::WARN, "a message") }
39
- expect(io.string).to match(/a message$/)
40
- end
41
-
42
- context "with structured data" do
43
- it "can be created with metadata" do
44
- expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true" })
45
- Logit.with_child({ child: "true" }) { |l| l.warn("a message") }
46
- end
47
-
48
- it "a message can be logged" do
49
- expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true" })
50
- Logit.with_child { |l| l.warn("a message", data: { child: "true" }) }
51
- end
52
-
53
- context "merges properly" do
54
- it "in the simple case" do
55
- expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true", meta: "data" })
56
- Logit.with_child(meta: "data") { |l| l.warn("a message", data: { child: "true" }) }
57
- end
58
-
59
- it "when overwriting" do
60
- expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true", meta: "overwritten" })
61
- Logit.with_child(meta: "data") { |l| l.warn("a message", data: { child: "true", meta: "overwritten" }) }
62
- end
63
- end
64
-
65
- context "when receiving a message from a child" do
66
- it "passes data on" do
67
- expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true", parent: "first" })
68
- child.metadata = { parent: "first" }
69
- child.with_child { |l| l.warn("a message", data: { child: "true" }) }
70
- end
71
-
72
- it "merges its own data" do
73
- expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[:warn], "a message", nil, data: { child: "true", parent: "second" })
74
- child.metadata = { parent: "first" }
75
- child.with_child { |l| l.warn("a message", data: { child: "true", parent: "second" }) }
76
- end
77
- end
78
- end
79
-
80
- context "sends a message to the parent" do
81
- %i{ debug info warn error fatal }.each do |level|
82
- it "at #{level}" do
83
- expect(Logit).to receive(:pass).with(Mixlib::Log::LEVELS[level], "a #{level} message", nil, data: {})
84
- Logit.level = level
85
- child.send(level, "a #{level} message")
86
- end
87
- end
88
- end
89
-
90
- context "can query the parent's level" do
91
- %i{ debug info warn error fatal }.each do |level|
92
- it "at #{level}" do
93
- query = "#{level}?".to_sym
94
- Logit.level = level
95
- expect(child.send(query)).to be(true)
96
- end
97
- end
98
- end
99
- end
@@ -1,64 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@chef.io>)
3
- # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require "time"
20
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
21
-
22
- RSpec.describe Mixlib::Log::Formatter do
23
- before(:each) do
24
- @formatter = Mixlib::Log::Formatter.new
25
- end
26
-
27
- it "should print raw strings with msg2str(string)" do
28
- expect(@formatter.msg2str("nuthin new")).to eq("nuthin new")
29
- end
30
-
31
- it "should format exceptions properly with msg2str(e)" do
32
- e = IOError.new("legendary roots crew")
33
- expect(@formatter.msg2str(e)).to eq("legendary roots crew (IOError)\n")
34
- end
35
-
36
- it "should format random objects via inspect with msg2str(Object)" do
37
- expect(@formatter.msg2str([ "black thought", "?uestlove" ])).to eq('["black thought", "?uestlove"]')
38
- end
39
-
40
- it "should return a formatted string with call" do
41
- time = Time.new
42
- Mixlib::Log::Formatter.show_time = true
43
- expect(@formatter.call("monkey", time, "test", "mos def")).to eq("[#{time.iso8601}] monkey: mos def\n")
44
- end
45
-
46
- it "should allow you to turn the time on and off in the output" do
47
- Mixlib::Log::Formatter.show_time = false
48
- expect(@formatter.call("monkey", Time.new, "test", "mos def")).to eq("monkey: mos def\n")
49
- end
50
-
51
- context "with structured data" do
52
- let(:data) { {} }
53
-
54
- it "should format a message" do
55
- data[:msg] = "nuthin new"
56
- expect(@formatter.msg2str(data)).to eq("nuthin new")
57
- end
58
-
59
- it "should format an exception" do
60
- data[:err] = IOError.new("legendary roots crew")
61
- expect(@formatter.msg2str(data)).to eq("legendary roots crew (IOError)\n")
62
- end
63
- end
64
- end
@@ -1,234 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@chef.io>)
3
- # Author:: Christopher Brown (<cb@chef.io>)
4
- # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
5
- # License:: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
-
20
- require "tempfile"
21
- require "stringio"
22
- require "spec_helper"
23
-
24
- class LoggerLike
25
- attr_accessor :level
26
- attr_reader :messages, :data
27
- def initialize
28
- @messages = ""
29
- @data = []
30
- end
31
-
32
- def add_data(severity, message = nil, progname = nil, data: {})
33
- @messages << message
34
- @data << data
35
- end
36
-
37
- def add(severity, message = nil, progname = nil, data: {})
38
- @messages << message
39
- end
40
-
41
- [:trace, :debug, :info, :warn, :error, :fatal].each do |method_name|
42
- class_eval(<<-E)
43
- def #{method_name}(message)
44
- @messages << message
45
- end
46
- E
47
- end
48
- end
49
-
50
- RSpec.describe Mixlib::Log do
51
-
52
- # Since we are testing class behaviour for an instance variable
53
- # that gets set once, we need to reset it prior to each example [cb]
54
- before(:each) do
55
- Logit.reset!
56
- end
57
-
58
- it "creates a logger using an IO object" do
59
- io = StringIO.new
60
- Logit.init(io)
61
- Logit << "foo"
62
- expect(io.string).to match(/foo/)
63
- end
64
-
65
- it "creates a logger with a file name" do
66
- Tempfile.open("chef-test-log") do |tempfile|
67
- Logit.init(tempfile.path)
68
- Logit << "bar"
69
- tempfile.rewind
70
- expect(tempfile.read).to match(/bar/)
71
- end
72
- end
73
-
74
- it "uses the logger provided when initialized with a logger like object" do
75
- logger = LoggerLike.new
76
- Logit.init(logger)
77
- Logit.level = :debug
78
- Logit.debug "qux"
79
- expect(logger.messages).to match(/qux/)
80
- end
81
-
82
- it "should re-initialize the logger if init is called again" do
83
- first_logdev, second_logdev = StringIO.new, StringIO.new
84
- Logit.init(first_logdev)
85
- Logit.fatal "FIRST"
86
- expect(first_logdev.string).to match(/FIRST/)
87
- Logit.init(second_logdev)
88
- Logit.fatal "SECOND"
89
- expect(first_logdev.string).to_not match(/SECOND/)
90
- expect(second_logdev.string).to match(/SECOND/)
91
- end
92
-
93
- it "knows that it's been configured" do
94
- Logit.init
95
- expect(Logit.configured?).to be true
96
- end
97
-
98
- it "should set the log level using the binding form, with :trace, :debug, :info, :warn, :error, or :fatal" do
99
- levels = {
100
- :trace => Mixlib::Log::TRACE,
101
- :debug => Mixlib::Log::DEBUG,
102
- :info => Mixlib::Log::INFO,
103
- :warn => Mixlib::Log::WARN,
104
- :error => Mixlib::Log::ERROR,
105
- :fatal => Mixlib::Log::FATAL,
106
- }
107
- levels.each do |symbol, constant|
108
- Logit.level = symbol
109
- expect(Logit.logger.level).to eq(constant)
110
- expect(Logit.level).to eq(symbol)
111
- end
112
- end
113
-
114
- it "passes blocks to the underlying logger object" do
115
- logdev = StringIO.new
116
- Logit.init(logdev)
117
- Logit.fatal { "the_message" }
118
- expect(logdev.string).to match(/the_message/)
119
- end
120
-
121
- it "should set the log level using the method form, with :trace, :debug, :info, :warn, :error, or :fatal" do
122
- levels = {
123
- :trace => Mixlib::Log::TRACE,
124
- :debug => Mixlib::Log::DEBUG,
125
- :info => Mixlib::Log::INFO,
126
- :warn => Mixlib::Log::WARN,
127
- :error => Mixlib::Log::ERROR,
128
- :fatal => Mixlib::Log::FATAL,
129
- }
130
- levels.each do |symbol, constant|
131
- Logit.level(symbol)
132
- expect(Logit.logger.level).to eq(constant)
133
- end
134
- end
135
-
136
- it "should raise an ArgumentError if you try and set the level to something strange using the binding form" do
137
- expect(lambda { Logit.level = :the_roots }).to raise_error(ArgumentError)
138
- end
139
-
140
- it "should raise an ArgumentError if you try and set the level to something strange using the method form" do
141
- expect(lambda { Logit.level(:the_roots) }).to raise_error(ArgumentError)
142
- end
143
-
144
- it "should pass other method calls directly to logger" do
145
- Logit.level = :debug
146
- expect(Logit).to be_debug
147
- expect(lambda { Logit.debug("Gimme some sugar!") }).to_not raise_error
148
- end
149
-
150
- it "should pass add method calls directly to logger" do
151
- logdev = StringIO.new
152
- Logit.init(logdev)
153
- Logit.level = :debug
154
- expect(Logit).to be_debug
155
- expect(lambda { Logit.add(Logger::DEBUG, "Gimme some sugar!") }).to_not raise_error
156
- expect(logdev.string).to match(/Gimme some sugar/)
157
- end
158
-
159
- it "should default to STDOUT if init is called with no arguments" do
160
- logger_mock = Struct.new(:formatter, :level).new
161
- expect(Logger).to receive(:new).with(STDOUT).and_return(logger_mock)
162
- Logit.init
163
- end
164
-
165
- it "should have by default a base log level of warn" do
166
- logger_mock = Struct.new(:formatter, :level).new
167
- expect(Logger).to receive(:new).and_return(logger_mock)
168
- Logit.init
169
- expect(Logit.level).to eq(:warn)
170
- end
171
-
172
- it "should close File logger" do
173
- opened_files_count_before = 0
174
- ObjectSpace.each_object(File) do |f|
175
- opened_files_count_before += 1 unless f.closed?
176
- end
177
- name = File.join(Dir.tmpdir, "logger.log")
178
- Logit.init(name)
179
- Logit.init(name)
180
- Logit.init(name)
181
- opened_files_count_after = 0
182
- ObjectSpace.each_object(File) do |f|
183
- opened_files_count_after += 1 unless f.closed?
184
- end
185
- expect(opened_files_count_after).to eq(opened_files_count_before + 1)
186
- end
187
-
188
- it "should not close IO logger" do
189
- opened_files_count_before = 0
190
- ObjectSpace.each_object(File) do |f|
191
- opened_files_count_before += 1 unless f.closed?
192
- end
193
- Tempfile.open("chef-test-log") do |file|
194
- Logit.init(file)
195
- Logit.init(file)
196
- Logit.init(file)
197
- opened_files_count_after = 0
198
- ObjectSpace.each_object(File) do |f|
199
- opened_files_count_after += 1 unless f.closed?
200
- end
201
- expect(opened_files_count_after).to eq(opened_files_count_before + 1)
202
- end
203
- end
204
-
205
- it "should return nil from its logging methods" do
206
- expect(Logger).to receive(:new).with(STDOUT) { double("a-quiet-logger").as_null_object }
207
- Logit.init
208
-
209
- aggregate_failures "returns nil from logging method" do
210
- expect(Logit.trace("hello")).to be_nil
211
- expect(Logit.debug("hello")).to be_nil
212
- expect(Logit.info("hello")).to be_nil
213
- expect(Logit.warn("hello")).to be_nil
214
- expect(Logit.error("hello")).to be_nil
215
- expect(Logit.fatal("hello")).to be_nil
216
- end
217
- end
218
-
219
- it "should set metadata correctly" do
220
- Logit.metadata = { test: "data" }
221
- expect(Logit.metadata).to eql({ test: "data" })
222
- end
223
-
224
- it "should format :trace level messages with TRACE: label" do
225
- logdev = StringIO.new
226
- Logit.init(logdev)
227
- Logit.level = :trace
228
- Logit.trace("this is a log message")
229
- aggregate_failures do
230
- expect(logdev.string).to_not match(/ANY:/)
231
- expect(logdev.string).to match(/TRACE:/)
232
- end
233
- end
234
- end
@@ -1,33 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@chef.io>)
3
- # Author:: Christopher Brown (<cb@chef.io>)
4
- # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
5
- # License:: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
-
20
- $TESTING = true
21
- $:.push File.join(File.dirname(__FILE__), "..", "lib")
22
-
23
- require "rspec"
24
- require "mixlib/log"
25
- require "mixlib/log/formatter"
26
-
27
- RSpec.configure do |config|
28
- config.disable_monkey_patching!
29
- end
30
-
31
- class Logit
32
- extend Mixlib::Log
33
- end