mixlib-log 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ module Mixlib
2
+ module Log
3
+ VERSION = "1.3.0"
4
+ end
5
+ end
data/lib/mixlib/log.rb CHANGED
@@ -7,9 +7,9 @@
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,14 +17,28 @@
17
17
  # limitations under the License.
18
18
 
19
19
  require 'logger'
20
+ require 'mixlib/log/version'
20
21
  require 'mixlib/log/formatter'
21
22
 
22
23
  module Mixlib
23
24
  module Log
24
-
25
- @logger = nil
26
- @@levels = { :debug=>Logger::DEBUG, :info=>Logger::INFO, :warn=>Logger::WARN, :error=>Logger::ERROR, :fatal=>Logger::FATAL}
27
-
25
+
26
+ @logger, @loggers = nil
27
+
28
+ LEVELS = { :debug=>Logger::DEBUG, :info=>Logger::INFO, :warn=>Logger::WARN, :error=>Logger::ERROR, :fatal=>Logger::FATAL}.freeze
29
+ LEVEL_NAMES = LEVELS.invert.freeze
30
+
31
+
32
+ def reset!
33
+ @logger, @loggers = nil, nil
34
+ end
35
+
36
+ # An Array of log devices that will be logged to. Defaults to just the default
37
+ # @logger log device, but you can push to this array to add more devices.
38
+ def loggers
39
+ @loggers ||= [logger]
40
+ end
41
+
28
42
  ##
29
43
  # init always returns a configured logger
30
44
  # and creates a new one if it doesn't yet exist
@@ -33,10 +47,27 @@ module Mixlib
33
47
  @logger || init
34
48
  end
35
49
 
36
- def logger=(value)
37
- @logger=value
50
+ # Sets the log device to +new_log_device+. Any additional loggers
51
+ # that had been added to the +loggers+ array will be cleared.
52
+ def logger=(new_log_device)
53
+ reset!
54
+ @logger=new_log_device
55
+ end
56
+
57
+ def use_log_devices(other)
58
+ if other.respond_to?(:loggers) && other.respond_to?(:logger)
59
+ @loggers = other.loggers
60
+ @logger = other.logger
61
+ elsif other.kind_of?(Array)
62
+ @loggers = other
63
+ @logger = other.first
64
+ else
65
+ msg = "#use_log_devices takes a Mixlib::Log object or array of log devices. " <<
66
+ "You gave: #{other.inspect}"
67
+ raise ArgumentError, msg
68
+ end
38
69
  end
39
-
70
+
40
71
  # Use Mixlib::Log.init when you want to set up the logger manually. Arguments to this method
41
72
  # get passed directly to Logger.new, so check out the documentation for the standard Logger class
42
73
  # to understand what to do here.
@@ -45,12 +76,13 @@ module Mixlib
45
76
  #
46
77
  # It also configures the Logger instance it creates to use the custom Mixlib::Log::Formatter class.
47
78
  def init(*opts)
48
- @logger = (opts.empty? ? Logger.new(STDOUT) : Logger.new(*opts))
49
- @logger.formatter = Mixlib::Log::Formatter.new()
79
+ reset!
80
+ @logger = logger_for(*opts)
81
+ @logger.formatter = Mixlib::Log::Formatter.new() if @logger.respond_to?(:formatter=)
50
82
  @logger.level = Logger::WARN
51
83
  @logger
52
84
  end
53
-
85
+
54
86
  # Sets the level for the Logger object by symbol. Valid arguments are:
55
87
  #
56
88
  # :debug
@@ -60,26 +92,70 @@ module Mixlib
60
92
  # :fatal
61
93
  #
62
94
  # Throws an ArgumentError if you feed it a bogus log level.
63
- def level=(l)
64
- lv = @@levels[l]
65
- raise ArgumentError, "Log level must be one of :debug, :info, :warn, :error, or :fatal" if lv.nil?
66
- logger.level = lv
95
+ def level=(new_level)
96
+ level_int = LEVEL_NAMES.key?(new_level) ? new_level : LEVELS[new_level]
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 }
67
99
  end
68
100
 
69
- def level(lv=nil)
70
- if lv.nil?
71
- @@levels.find() {|l| logger.level==l[1]}[0]
101
+ def level(new_level=nil)
102
+ if new_level.nil?
103
+ LEVEL_NAMES[logger.level]
72
104
  else
73
- self.level=(lv)
105
+ self.level=(new_level)
74
106
  end
75
107
  end
76
-
108
+
109
+ # Define the standard logger methods on this class programmatically.
110
+ # No need to incur method_missing overhead on every log call.
111
+ [:debug, :info, :warn, :error, :fatal].each do |method_name|
112
+ class_eval(<<-METHOD_DEFN, __FILE__, __LINE__)
113
+ def #{method_name}(msg=nil, &block)
114
+ loggers.each {|l| l.#{method_name}(msg, &block) }
115
+ end
116
+ METHOD_DEFN
117
+ end
118
+
119
+ # Define the methods to interrogate the logger for the current log level.
120
+ # Note that we *only* query the default logger (@logger) and not any other
121
+ # loggers that may have been added, even though it is possible to configure
122
+ # two (or more) loggers at different log levels.
123
+ [:debug?, :info?, :warn?, :error?, :fatal?].each do |method_name|
124
+ class_eval(<<-METHOD_DEFN, __FILE__, __LINE__)
125
+ def #{method_name}
126
+ logger.#{method_name}
127
+ end
128
+ METHOD_DEFN
129
+ end
130
+
131
+ def <<(msg)
132
+ loggers.each {|l| l << msg }
133
+ end
134
+
135
+ def add(severity, message = nil, progname = nil, &block)
136
+ loggers.each {|l| l.add(severity, message = nil, progname = nil, &block) }
137
+ end
138
+
139
+ alias :log :add
140
+
77
141
  # Passes any other method calls on directly to the underlying Logger object created with init. If
78
- # this method gets hit before a call to Mixlib::Logger.init has been made, it will call
142
+ # this method gets hit before a call to Mixlib::Logger.init has been made, it will call
79
143
  # Mixlib::Logger.init() with no arguments.
80
144
  def method_missing(method_symbol, *args, &block)
81
- logger.send(method_symbol, *args, &block)
145
+ loggers.each {|l| l.send(method_symbol, *args, &block) }
146
+ end
147
+
148
+ private
149
+
150
+ def logger_for(*opts)
151
+ if opts.empty?
152
+ Logger.new(STDOUT)
153
+ elsif LEVELS.keys.inject(true) {|quacks, level| quacks && opts.first.respond_to?(level)}
154
+ opts.first
155
+ else
156
+ Logger.new(*opts)
157
+ end
82
158
  end
83
-
159
+
84
160
  end
85
161
  end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixlib-log
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 2
8
- - 0
9
- version: 1.2.0
4
+ prerelease:
5
+ version: 1.3.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - Opscode, Inc.
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-10-19 00:00:00 -07:00
13
+ date: 2011-03-23 00:00:00 -07:00
18
14
  default_executable:
19
15
  dependencies: []
20
16
 
@@ -25,32 +21,23 @@ executables: []
25
21
  extensions: []
26
22
 
27
23
  extra_rdoc_files:
28
- - LICENSE
29
24
  - README.rdoc
30
- files:
31
- - .gitignore
32
25
  - LICENSE
33
26
  - NOTICE
34
- - README.rdoc
35
- - Rakefile
36
- - VERSION.yml
37
- - features/log.feature
38
- - features/steps/log.rb
39
- - features/support/env.rb
40
- - features/support/logit.rb
41
- - lib/mixlib/log.rb
27
+ files:
42
28
  - lib/mixlib/log/formatter.rb
43
- - spec/mixlib/log/formatter_spec.rb
44
- - spec/mixlib/log_spec.rb
45
- - spec/spec.opts
46
- - spec/spec_helper.rb
29
+ - lib/mixlib/log/version.rb
30
+ - lib/mixlib/log.rb
31
+ - README.rdoc
32
+ - LICENSE
33
+ - NOTICE
47
34
  has_rdoc: true
48
35
  homepage: http://www.opscode.com
49
36
  licenses: []
50
37
 
51
38
  post_install_message:
52
- rdoc_options:
53
- - --charset=UTF-8
39
+ rdoc_options: []
40
+
54
41
  require_paths:
55
42
  - lib
56
43
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -58,25 +45,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
45
  requirements:
59
46
  - - ">="
60
47
  - !ruby/object:Gem::Version
61
- segments:
62
- - 0
63
48
  version: "0"
64
49
  required_rubygems_version: !ruby/object:Gem::Requirement
65
50
  none: false
66
51
  requirements:
67
52
  - - ">="
68
53
  - !ruby/object:Gem::Version
69
- segments:
70
- - 0
71
54
  version: "0"
72
55
  requirements: []
73
56
 
74
57
  rubyforge_project:
75
- rubygems_version: 1.3.7
58
+ rubygems_version: 1.6.2
76
59
  signing_key:
77
60
  specification_version: 3
78
61
  summary: A gem that provides a simple mixin for log functionality
79
- test_files:
80
- - spec/mixlib/log/formatter_spec.rb
81
- - spec/mixlib/log_spec.rb
82
- - spec/spec_helper.rb
62
+ test_files: []
63
+
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- *.sw?
2
- .DS_Store
3
- coverage
4
- rdoc
5
- pkg
data/Rakefile DELETED
@@ -1,69 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "mixlib-log"
8
- gem.summary = "A gem that provides a simple mixin for log functionality"
9
- gem.email = "info@opscode.com"
10
- gem.homepage = "http://www.opscode.com"
11
- gem.authors = ["Opscode, Inc."]
12
- gem.files.include %w{ bin/* lib/**/* }
13
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
- end
15
- Jeweler::GemcutterTasks.new
16
- rescue LoadError
17
- STDERR.puts
18
- STDERR.puts "Jeweler is not installed. (sudo) gem install jeweler to use gem packaging tasks"
19
- STDERR.puts
20
- end
21
-
22
- begin
23
- require 'spec/rake/spectask'
24
- Spec::Rake::SpecTask.new(:spec) do |spec|
25
- spec.libs << 'lib' << 'spec'
26
- spec.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
27
- spec.spec_files = FileList['spec/**/*_spec.rb']
28
- end
29
-
30
- Spec::Rake::SpecTask.new(:rcov) do |spec|
31
- spec.libs << 'lib' << 'spec'
32
- spec.pattern = 'spec/**/*_spec.rb'
33
- spec.rcov = true
34
- end
35
- rescue LoadError
36
- task :spec do
37
- abort "Rspec is not available. (sudo) gem install rspec to run unit tests"
38
- end
39
- end
40
-
41
-
42
- begin
43
- require 'cucumber/rake/task'
44
- Cucumber::Rake::Task.new(:features)
45
- rescue LoadError
46
- task :features do
47
- abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
48
- end
49
- end
50
-
51
- task :default => :spec
52
-
53
- require 'rake/rdoctask'
54
- require 'yaml'
55
-
56
- Rake::RDocTask.new do |rdoc|
57
- if File.exist?('VERSION.yml')
58
- config = YAML.load(File.read('VERSION.yml'))
59
- version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
60
- else
61
- version = ""
62
- end
63
-
64
- rdoc.rdoc_dir = 'rdoc'
65
- rdoc.title = "mixlib-log #{version}"
66
- rdoc.rdoc_files.include('README*')
67
- rdoc.rdoc_files.include('lib/**/*.rb')
68
- end
69
-
data/VERSION.yml DELETED
@@ -1,5 +0,0 @@
1
- ---
2
- :major: 1
3
- :minor: 2
4
- :patch: 0
5
- :build:
data/features/log.feature DELETED
@@ -1,37 +0,0 @@
1
- Feature: Log output
2
- In order to keep a record of application specific information
3
- As a developer
4
- I want to publish information through a configurable log interface
5
-
6
- Scenario: Log a message at the debug level
7
- Given a base log level of 'debug'
8
- When the message 'this goes out' is sent at the 'debug' level
9
- Then the regex '\[.+\] DEBUG: this goes out' should be logged
10
-
11
- Scenario: Log a message at the info level
12
- Given a base log level of 'info'
13
- When the message 'this goes out' is sent at the 'info' level
14
- Then the regex '\[.+\] INFO: this goes out' should be logged
15
-
16
- Scenario: Log a message at the warn level
17
- Given a base log level of 'warn'
18
- When the message 'this goes out' is sent at the 'warn' level
19
- Then the regex '\[.+\] WARN: this goes out' should be logged
20
-
21
- Scenario: Log a message at the error level
22
- Given a base log level of 'error'
23
- When the message 'this goes out' is sent at the 'error' level
24
- Then the regex '\[.+\] ERROR: this goes out' should be logged
25
-
26
- Scenario: Log a message at the fatal level
27
- Given a base log level of 'fatal'
28
- When the message 'this goes out' is sent at the 'fatal' level
29
- Then the regex '\[.+\] FATAL: this goes out' should be logged
30
-
31
- Scenario: Log messages below the current threshold should not appear
32
- Given a base log level of 'fatal'
33
- When the message 'this goes out' is sent at the 'error' level
34
- And the message 'this goes out' is sent at the 'warn' level
35
- And the message 'this goes out' is sent at the 'info' level
36
- And the message 'this goes out' is sent at the 'debug' level
37
- Then nothing should be logged
@@ -1,48 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, 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
- Given /^a base log level of '(.+)'$/ do |level|
20
- Logit.level = level.to_sym
21
- end
22
-
23
- When /^the message '(.+)' is sent at the '(.+)' level$/ do |message, level|
24
- case level.to_sym
25
- when :debug
26
- Logit.debug(message)
27
- when :info
28
- Logit.info(message)
29
- when :warn
30
- Logit.warn(message)
31
- when :error
32
- Logit.error(message)
33
- when :fatal
34
- Logit.fatal(message)
35
- else
36
- raise ArgumentError, "Level is not one of debug, info, warn, error, or fatal"
37
- end
38
- end
39
-
40
- Then /^the regex '(.+)' should be logged$/ do |regex_string|
41
- regex = Regexp.new(regex_string, Regexp::MULTILINE)
42
- regex.match(@output).should_not == nil
43
- end
44
-
45
- Then /^nothing should be logged$/ do
46
- @output.should == ""
47
- end
48
-
@@ -1,46 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, 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
- $: << File.join(File.dirname(__FILE__), '..', '..', 'lib')
20
-
21
- require 'spec/expectations'
22
- require 'mixlib/log'
23
- require 'tmpdir'
24
- require 'stringio'
25
-
26
- class MyWorld
27
- def initialize
28
- @tmpdir = File.join(Dir.tmpdir, "mixlib_log")
29
- @output = ''
30
- @output_io = StringIO.new(@output)
31
- Logit.init(@output_io)
32
- end
33
- end
34
-
35
- World do
36
- MyWorld.new
37
- end
38
-
39
- Before do
40
- system("mkdir -p #{@tmpdir}")
41
- end
42
-
43
- After do
44
- system("rm -rf #{@tmpdir}")
45
- end
46
-
@@ -1,21 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, 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
- class Logit
20
- extend Mixlib::Log
21
- end
@@ -1,51 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, 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
- 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
- @formatter.msg2str("nuthin new").should == "nuthin new"
29
- end
30
-
31
- it "should format exceptions properly with msg2str(e)" do
32
- e = IOError.new("legendary roots crew")
33
- @formatter.msg2str(e).should == "legendary roots crew (IOError)\n"
34
- end
35
-
36
- it "should format random objects via inspect with msg2str(Object)" do
37
- @formatter.msg2str([ "black thought", "?uestlove" ]).should == '["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
- @formatter.call("monkey", time, "test", "mos def").should == "[#{time.rfc2822}] 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
- @formatter.call("monkey", Time.new, "test", "mos def").should == "monkey: mos def\n"
49
- end
50
-
51
- end
@@ -1,107 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Author:: Christopher Brown (<cb@opscode.com>)
4
- # Copyright:: Copyright (c) 2008 Opscode, 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 File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
22
-
23
- describe Mixlib::Log do
24
-
25
- # Since we are testing class behaviour for an instance variable
26
- # that gets set once, we need to reset it prior to each example [cb]
27
- before(:each) do
28
- Logit.instance_variable_set("@logger",nil)
29
- end
30
-
31
- it "should accept regular options to Logger.new via init" do
32
- Tempfile.open("chef-test-log") do |tf|
33
- lambda { Logit.init(STDOUT) }.should_not raise_error
34
- lambda { Logit.init(tf) }.should_not raise_error
35
- end
36
- end
37
-
38
- it "should re-initialize the logger if init is called again" do
39
- first_logdev, second_logdev = StringIO.new, StringIO.new
40
- Logit.init(first_logdev)
41
- Logit.fatal "FIRST"
42
- first_logdev.string.should match(/FIRST/)
43
- Logit.init(second_logdev)
44
- Logit.fatal "SECOND"
45
- first_logdev.string.should_not match(/SECOND/)
46
- second_logdev.string.should match(/SECOND/)
47
- end
48
-
49
- it "should set the log level using the binding form, with :debug, :info, :warn, :error, or :fatal" do
50
- levels = {
51
- :debug => Logger::DEBUG,
52
- :info => Logger::INFO,
53
- :warn => Logger::WARN,
54
- :error => Logger::ERROR,
55
- :fatal => Logger::FATAL
56
- }
57
- levels.each do |symbol, constant|
58
- Logit.level = symbol
59
- Logit.logger.level.should == constant
60
- Logit.level.should == symbol
61
- end
62
- end
63
-
64
- it "passes blocks to the underlying logger object" do
65
- logdev = StringIO.new
66
- Logit.init(logdev)
67
- Logit.fatal { "the_message" }
68
- logdev.string.should match(/the_message/)
69
- end
70
-
71
-
72
- it "should set the log level using the method form, with :debug, :info, :warn, :error, or :fatal" do
73
- levels = {
74
- :debug => Logger::DEBUG,
75
- :info => Logger::INFO,
76
- :warn => Logger::WARN,
77
- :error => Logger::ERROR,
78
- :fatal => Logger::FATAL
79
- }
80
- levels.each do |symbol, constant|
81
- Logit.level(symbol)
82
- Logit.logger.level.should == constant
83
- end
84
- end
85
-
86
- it "should raise an ArgumentError if you try and set the level to something strange using the binding form" do
87
- lambda { Logit.level = :the_roots }.should raise_error(ArgumentError)
88
- end
89
-
90
- it "should raise an ArgumentError if you try and set the level to something strange using the method form" do
91
- lambda { Logit.level(:the_roots) }.should raise_error(ArgumentError)
92
- end
93
-
94
- it "should pass other method calls directly to logger" do
95
- Logit.level = :debug
96
- Logit.should be_debug
97
- lambda { Logit.debug("Gimme some sugar!") }.should_not raise_error
98
- end
99
-
100
- it "should default to STDOUT if init is called with no arguments" do
101
- logger_mock = mock(Logger, :null_object => true)
102
- Logger.stub!(:new).and_return(logger_mock)
103
- Logger.should_receive(:new).with(STDOUT).and_return(logger_mock)
104
- Logit.init
105
- end
106
-
107
- end
data/spec/spec.opts DELETED
@@ -1,4 +0,0 @@
1
- --colour
2
- --format specdoc
3
- --loadby mtime
4
- --reverse
data/spec/spec_helper.rb DELETED
@@ -1,28 +0,0 @@
1
- #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Author:: Christopher Brown (<cb@opscode.com>)
4
- # Copyright:: Copyright (c) 2008 Opscode, 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 'mixlib/log'
24
- require 'mixlib/log/formatter'
25
-
26
- class Logit
27
- extend Mixlib::Log
28
- end