mixlib-log 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,7 +31,7 @@ module Mixlib
31
31
  # Otherwise, doesn't print the time.
32
32
  def call(severity, time, progname, msg)
33
33
  if @@show_time
34
- sprintf("[%s] %s: %s\n", time.rfc2822(), severity, msg2str(msg))
34
+ sprintf("[%s] %s: %s\n", time.iso8601(), severity, msg2str(msg))
35
35
  else
36
36
  sprintf("%s: %s\n", severity, msg2str(msg))
37
37
  end
@@ -53,4 +53,4 @@ module Mixlib
53
53
  end
54
54
  end
55
55
  end
56
- end
56
+ end
@@ -1,5 +1,5 @@
1
1
  module Mixlib
2
2
  module Log
3
- VERSION = "1.3.0"
3
+ VERSION = "1.4.0"
4
4
  end
5
5
  end
data/lib/mixlib/log.rb CHANGED
@@ -72,7 +72,7 @@ module Mixlib
72
72
  # get passed directly to Logger.new, so check out the documentation for the standard Logger class
73
73
  # to understand what to do here.
74
74
  #
75
- # If this method is called with no arguments, it will log to STDOUT at the :info level.
75
+ # If this method is called with no arguments, it will log to STDOUT at the :warn level.
76
76
  #
77
77
  # It also configures the Logger instance it creates to use the custom Mixlib::Log::Formatter class.
78
78
  def init(*opts)
@@ -0,0 +1,51 @@
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.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
+ @formatter.call("monkey", Time.new, "test", "mos def").should == "monkey: mos def\n"
49
+ end
50
+
51
+ end
@@ -0,0 +1,147 @@
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 'stringio'
22
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
23
+
24
+ class LoggerLike
25
+ attr_accessor :level
26
+ attr_reader :messages
27
+ def initialize
28
+ @messages = ""
29
+ end
30
+
31
+ [:debug, :info, :warn, :error, :fatal].each do |method_name|
32
+ class_eval(<<-E)
33
+ def #{method_name}(message)
34
+ @messages << message
35
+ end
36
+ E
37
+ end
38
+ end
39
+
40
+ describe Mixlib::Log do
41
+
42
+ # Since we are testing class behaviour for an instance variable
43
+ # that gets set once, we need to reset it prior to each example [cb]
44
+ before(:each) do
45
+ Logit.reset!
46
+ end
47
+
48
+ it "creates a logger using an IO object" do
49
+ io = StringIO.new
50
+ Logit.init(io)
51
+ Logit << "foo"
52
+ io.string.should match(/foo/)
53
+ end
54
+
55
+ it "creates a logger with a file name" do
56
+ Tempfile.open("chef-test-log") do |tempfile|
57
+ Logit.init(tempfile.path)
58
+ Logit << "bar"
59
+ tempfile.rewind
60
+ tempfile.read.should match(/bar/)
61
+ end
62
+ end
63
+
64
+ it "uses the logger provided when initialized with a logger like object" do
65
+ logger = LoggerLike.new
66
+ Logit.init(logger)
67
+ Logit.debug "qux"
68
+ logger.messages.should match(/qux/)
69
+ end
70
+
71
+ it "should re-initialize the logger if init is called again" do
72
+ first_logdev, second_logdev = StringIO.new, StringIO.new
73
+ Logit.init(first_logdev)
74
+ Logit.fatal "FIRST"
75
+ first_logdev.string.should match(/FIRST/)
76
+ Logit.init(second_logdev)
77
+ Logit.fatal "SECOND"
78
+ first_logdev.string.should_not match(/SECOND/)
79
+ second_logdev.string.should match(/SECOND/)
80
+ end
81
+
82
+ it "should set the log level using the binding form, with :debug, :info, :warn, :error, or :fatal" do
83
+ levels = {
84
+ :debug => Logger::DEBUG,
85
+ :info => Logger::INFO,
86
+ :warn => Logger::WARN,
87
+ :error => Logger::ERROR,
88
+ :fatal => Logger::FATAL
89
+ }
90
+ levels.each do |symbol, constant|
91
+ Logit.level = symbol
92
+ Logit.logger.level.should == constant
93
+ Logit.level.should == symbol
94
+ end
95
+ end
96
+
97
+ it "passes blocks to the underlying logger object" do
98
+ logdev = StringIO.new
99
+ Logit.init(logdev)
100
+ Logit.fatal { "the_message" }
101
+ logdev.string.should match(/the_message/)
102
+ end
103
+
104
+
105
+ it "should set the log level using the method form, with :debug, :info, :warn, :error, or :fatal" do
106
+ levels = {
107
+ :debug => Logger::DEBUG,
108
+ :info => Logger::INFO,
109
+ :warn => Logger::WARN,
110
+ :error => Logger::ERROR,
111
+ :fatal => Logger::FATAL
112
+ }
113
+ levels.each do |symbol, constant|
114
+ Logit.level(symbol)
115
+ Logit.logger.level.should == constant
116
+ end
117
+ end
118
+
119
+ 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 }.should raise_error(ArgumentError)
121
+ end
122
+
123
+ 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) }.should raise_error(ArgumentError)
125
+ end
126
+
127
+ it "should pass other method calls directly to logger" do
128
+ Logit.level = :debug
129
+ Logit.should be_debug
130
+ lambda { Logit.debug("Gimme some sugar!") }.should_not raise_error
131
+ end
132
+
133
+ it "should default to STDOUT if init is called with no arguments" do
134
+ logger_mock = Struct.new(:formatter, :level).new
135
+ Logger.stub!(:new).and_return(logger_mock)
136
+ Logger.should_receive(:new).with(STDOUT).and_return(logger_mock)
137
+ Logit.init
138
+ end
139
+
140
+ it "should have by default a base log level of warn" do
141
+ logger_mock = Struct.new(:formatter, :level).new
142
+ Logger.stub!(:new).and_return(logger_mock)
143
+ Logit.init
144
+ Logit.level.should eql(:warn)
145
+ end
146
+
147
+ end
@@ -0,0 +1,29 @@
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 'rspec'
24
+ require 'mixlib/log'
25
+ require 'mixlib/log/formatter'
26
+
27
+ class Logit
28
+ extend Mixlib::Log
29
+ end
metadata CHANGED
@@ -1,63 +1,104 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mixlib-log
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
4
5
  prerelease:
5
- version: 1.3.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Opscode, Inc.
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-03-23 00:00:00 -07:00
14
- default_executable:
15
- dependencies: []
16
-
12
+ date: 2012-06-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.2.2
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.2.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.10.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.10.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: cucumber
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.0
17
62
  description:
18
63
  email: info@opscode.com
19
64
  executables: []
20
-
21
65
  extensions: []
22
-
23
- extra_rdoc_files:
66
+ extra_rdoc_files:
24
67
  - README.rdoc
25
68
  - LICENSE
26
69
  - NOTICE
27
- files:
28
- - lib/mixlib/log/formatter.rb
29
- - lib/mixlib/log/version.rb
70
+ files:
30
71
  - lib/mixlib/log.rb
72
+ - lib/mixlib/log/version.rb
73
+ - lib/mixlib/log/formatter.rb
74
+ - spec/spec_helper.rb
75
+ - spec/mixlib/log_spec.rb
76
+ - spec/mixlib/log/formatter_spec.rb
31
77
  - README.rdoc
32
78
  - LICENSE
33
79
  - NOTICE
34
- has_rdoc: true
35
80
  homepage: http://www.opscode.com
36
81
  licenses: []
37
-
38
82
  post_install_message:
39
83
  rdoc_options: []
40
-
41
- require_paths:
84
+ require_paths:
42
85
  - lib
43
- required_ruby_version: !ruby/object:Gem::Requirement
86
+ required_ruby_version: !ruby/object:Gem::Requirement
44
87
  none: false
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: "0"
49
- required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
93
  none: false
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: "0"
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
55
98
  requirements: []
56
-
57
99
  rubyforge_project:
58
- rubygems_version: 1.6.2
100
+ rubygems_version: 1.8.23
59
101
  signing_key:
60
102
  specification_version: 3
61
103
  summary: A gem that provides a simple mixin for log functionality
62
104
  test_files: []
63
-