mixlib-log 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/NOTICE ADDED
@@ -0,0 +1,27 @@
1
+ Mixin::Log NOTICE
2
+ =================
3
+
4
+ Developed at Opscode (http://www.opscode.com).
5
+
6
+ * Copyright 2009, Opscode, Inc. <legal@opscode.com>
7
+
8
+ Mixin::Log incorporates code from Chef. The Chef notice file follows:
9
+
10
+ Chef NOTICE
11
+ ===========
12
+
13
+ Developed at Opscode (http://www.opscode.com).
14
+
15
+ Contributors and Copyright holders:
16
+
17
+ * Copyright 2008, Adam Jacob <adam@opscode.com>
18
+ * Copyright 2008, Arjuna Christensen <aj@hjksolutions.com>
19
+ * Copyright 2008, Bryan McLellan <btm@loftninjas.org>
20
+ * Copyright 2008, Ezra Zygmuntowicz <ezra@engineyard.com>
21
+ * Copyright 2009, Sean Cribbs <seancribbs@gmail.com>
22
+ * Copyright 2009, Christopher Brown <cb@opscode.com>
23
+ * Copyright 2009, Thom May <thom@clearairturbulence.org>
24
+
25
+ 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/Rakefile CHANGED
@@ -9,11 +9,12 @@ begin
9
9
  gem.email = "info@opscode.com"
10
10
  gem.homepage = "http://www.opscode.com"
11
11
  gem.authors = ["Opscode, Inc."]
12
-
12
+ gem.files.include %w{ bin/* lib/**/* }
13
13
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
14
  end
15
+ Jeweler::GemcutterTasks.new
15
16
  rescue LoadError
16
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install gemcutter jeweler (installs jeweler from gemcutter)"
17
18
  end
18
19
 
19
20
  require 'spec/rake/spectask'
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
- :minor: 0
4
- :patch: 3
3
+ :minor: 1
4
+ :patch: 0
@@ -0,0 +1,37 @@
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
@@ -0,0 +1,48 @@
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
+
@@ -0,0 +1,46 @@
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
+
@@ -0,0 +1,21 @@
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,5 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Christopher Brown (<cb@opscode.com>)
3
4
  # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
@@ -15,16 +16,15 @@
15
16
  # See the License for the specific language governing permissions and
16
17
  # limitations under the License.
17
18
 
18
- require 'mixlib/log/formatter'
19
19
  require 'logger'
20
+ require 'mixlib/log/formatter'
20
21
 
21
22
  module Mixlib
22
23
  module Log
23
24
 
24
25
  @logger = nil
26
+ @@levels = { :debug=>Logger::DEBUG, :info=>Logger::INFO, :warn=>Logger::WARN, :error=>Logger::ERROR, :fatal=>Logger::FATAL}
25
27
 
26
- attr_writer :logger #:nodoc
27
-
28
28
  ##
29
29
  # init always returns a configured logger
30
30
  # and creates a new one if it doesn't yet exist
@@ -32,6 +32,10 @@ module Mixlib
32
32
  def logger
33
33
  init
34
34
  end
35
+
36
+ def logger=(value)
37
+ @logger=value
38
+ end
35
39
 
36
40
  # Use Mixlib::Log.init when you want to set up the logger manually. Arguments to this method
37
41
  # get passed directly to Logger.new, so check out the documentation for the standard Logger class
@@ -44,6 +48,7 @@ module Mixlib
44
48
  if @logger.nil?
45
49
  @logger = (opts.empty? ? Logger.new(STDOUT) : Logger.new(*opts))
46
50
  @logger.formatter = Mixlib::Log::Formatter.new()
51
+ @logger.level = Logger::WARN
47
52
  end
48
53
  @logger
49
54
  end
@@ -57,10 +62,18 @@ module Mixlib
57
62
  # :fatal
58
63
  #
59
64
  # Throws an ArgumentError if you feed it a bogus log level.
60
- def level(loglevel=:warn)
61
- level = { :debug=>Logger::DEBUG, :info=>Logger::INFO, :warn=>Logger::WARN, :error=>Logger::ERROR, :fatal=>Logger::FATAL}[loglevel]
62
- raise ArgumentError, "Log level must be one of :debug, :info, :warn, :error, or :fatal" if level.nil?
63
- logger.level = level
65
+ def level=(l)
66
+ lv = @@levels[l]
67
+ raise ArgumentError, "Log level must be one of :debug, :info, :warn, :error, or :fatal" if lv.nil?
68
+ logger.level = lv
69
+ end
70
+
71
+ def level(lv=nil)
72
+ if lv.nil?
73
+ @@levels.find() {|l| logger.level==l[1]}[0]
74
+ else
75
+ self.level=(lv)
76
+ end
64
77
  end
65
78
 
66
79
  # Passes any other method calls on directly to the underlying Logger object created with init. If
@@ -1,5 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Christopher Brown (<cb@opscode.com>)
3
4
  # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
@@ -34,7 +35,22 @@ describe Mixlib::Log do
34
35
  lambda { Logit.init(tf) }.should_not raise_error
35
36
  end
36
37
 
37
- it "should set the log level with :debug, :info, :warn, :error, or :fatal" do
38
+ it "should set the log level using the binding form, with :debug, :info, :warn, :error, or :fatal" do
39
+ levels = {
40
+ :debug => Logger::DEBUG,
41
+ :info => Logger::INFO,
42
+ :warn => Logger::WARN,
43
+ :error => Logger::ERROR,
44
+ :fatal => Logger::FATAL
45
+ }
46
+ levels.each do |symbol, constant|
47
+ Logit.level = symbol
48
+ Logit.logger.level.should == constant
49
+ Logit.level.should == symbol
50
+ end
51
+ end
52
+
53
+ it "should set the log level using the method form, with :debug, :info, :warn, :error, or :fatal" do
38
54
  levels = {
39
55
  :debug => Logger::DEBUG,
40
56
  :info => Logger::INFO,
@@ -48,12 +64,16 @@ describe Mixlib::Log do
48
64
  end
49
65
  end
50
66
 
51
- it "should raise an ArgumentError if you try and set the level to something strange" do
67
+ it "should raise an ArgumentError if you try and set the level to something strange using the binding form" do
68
+ lambda { Logit.level = :the_roots }.should raise_error(ArgumentError)
69
+ end
70
+
71
+ it "should raise an ArgumentError if you try and set the level to something strange using the method form" do
52
72
  lambda { Logit.level(:the_roots) }.should raise_error(ArgumentError)
53
73
  end
54
74
 
55
75
  it "should pass other method calls directly to logger" do
56
- Logit.level(:debug)
76
+ Logit.level = :debug
57
77
  Logit.should be_debug
58
78
  lambda { Logit.debug("Gimme some sugar!") }.should_not raise_error
59
79
  end
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format specdoc
3
+ --loadby mtime
4
+ --reverse
@@ -1,3 +1,22 @@
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
+
1
20
  $TESTING=true
2
21
  $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
22
 
@@ -5,5 +24,5 @@ require 'mixlib/log'
5
24
  require 'mixlib/log/formatter'
6
25
 
7
26
  class Logit
8
- extend(Mixlib::Log)
9
- end
27
+ extend Mixlib::Log
28
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixlib-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 1
8
+ - 0
9
+ version: 1.1.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Opscode, Inc.
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-05-12 00:00:00 +12:00
17
+ date: 2010-02-28 00:00:00 -08:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -23,14 +28,21 @@ extra_rdoc_files:
23
28
  - LICENSE
24
29
  - README.rdoc
25
30
  files:
31
+ - .gitignore
26
32
  - LICENSE
33
+ - NOTICE
27
34
  - README.rdoc
28
35
  - Rakefile
29
36
  - VERSION.yml
37
+ - features/log.feature
38
+ - features/steps/log.rb
39
+ - features/support/env.rb
40
+ - features/support/logit.rb
30
41
  - lib/mixlib/log.rb
31
42
  - lib/mixlib/log/formatter.rb
32
43
  - spec/mixlib/log/formatter_spec.rb
33
44
  - spec/mixlib/log_spec.rb
45
+ - spec/spec.opts
34
46
  - spec/spec_helper.rb
35
47
  has_rdoc: true
36
48
  homepage: http://www.opscode.com
@@ -45,18 +57,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
57
  requirements:
46
58
  - - ">="
47
59
  - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
48
62
  version: "0"
49
- version:
50
63
  required_rubygems_version: !ruby/object:Gem::Requirement
51
64
  requirements:
52
65
  - - ">="
53
66
  - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
54
69
  version: "0"
55
- version:
56
70
  requirements: []
57
71
 
58
72
  rubyforge_project:
59
- rubygems_version: 1.3.5
73
+ rubygems_version: 1.3.6
60
74
  signing_key:
61
75
  specification_version: 3
62
76
  summary: A gem that provides a simple mixin for log functionality