chef 0.9.18 → 0.10.0.beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. data/README.rdoc +0 -3
  2. data/distro/arch/etc/rc.d/chef-server +0 -4
  3. data/distro/arch/etc/rc.d/chef-server-webui +0 -4
  4. data/distro/arch/etc/rc.d/chef-solr +0 -4
  5. data/distro/arch/etc/rc.d/chef-solr-indexer +0 -4
  6. data/lib/chef.rb +3 -3
  7. data/lib/chef/api_client.rb +1 -1
  8. data/lib/chef/application.rb +11 -1
  9. data/lib/chef/application/client.rb +18 -22
  10. data/lib/chef/application/knife.rb +28 -29
  11. data/lib/chef/application/solo.rb +14 -12
  12. data/lib/chef/client.rb +112 -54
  13. data/lib/chef/config.rb +4 -0
  14. data/lib/chef/cookbook/chefignore.rb +66 -0
  15. data/lib/chef/cookbook/cookbook_collection.rb +6 -5
  16. data/lib/chef/cookbook/cookbook_version_loader.rb +151 -0
  17. data/lib/chef/cookbook/file_system_file_vendor.rb +10 -8
  18. data/lib/chef/cookbook/metadata.rb +200 -108
  19. data/lib/chef/cookbook_loader.rb +39 -163
  20. data/lib/chef/cookbook_uploader.rb +100 -78
  21. data/lib/chef/cookbook_version.rb +92 -47
  22. data/lib/chef/cookbook_version_selector.rb +163 -0
  23. data/lib/chef/couchdb.rb +9 -1
  24. data/lib/chef/data_bag.rb +1 -1
  25. data/lib/chef/data_bag_item.rb +1 -1
  26. data/lib/chef/encrypted_data_bag_item.rb +126 -0
  27. data/lib/chef/environment.rb +386 -0
  28. data/lib/chef/exceptions.rb +82 -1
  29. data/lib/chef/index_queue/amqp_client.rb +15 -12
  30. data/lib/chef/index_queue/indexable.rb +38 -4
  31. data/lib/chef/json_compat.rb +3 -3
  32. data/lib/chef/knife.rb +97 -202
  33. data/lib/chef/knife/bootstrap.rb +27 -61
  34. data/lib/chef/knife/bootstrap/archlinux-gems.erb +4 -2
  35. data/lib/chef/knife/bootstrap/centos5-gems.erb +6 -15
  36. data/lib/chef/knife/bootstrap/fedora13-gems.erb +3 -4
  37. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -2
  38. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +6 -5
  39. data/lib/chef/knife/client_bulk_delete.rb +6 -3
  40. data/lib/chef/knife/client_create.rb +13 -10
  41. data/lib/chef/knife/client_delete.rb +10 -7
  42. data/lib/chef/knife/client_edit.rb +9 -6
  43. data/lib/chef/knife/client_list.rb +8 -5
  44. data/lib/chef/knife/client_reregister.rb +9 -6
  45. data/lib/chef/knife/client_show.rb +9 -6
  46. data/lib/chef/knife/configure.rb +15 -19
  47. data/lib/chef/knife/configure_client.rb +4 -4
  48. data/lib/chef/knife/cookbook_bulk_delete.rb +11 -8
  49. data/lib/chef/knife/cookbook_create.rb +120 -55
  50. data/lib/chef/knife/cookbook_delete.rb +18 -12
  51. data/lib/chef/knife/cookbook_download.rb +10 -6
  52. data/lib/chef/knife/cookbook_list.rb +15 -6
  53. data/lib/chef/knife/cookbook_metadata.rb +41 -21
  54. data/lib/chef/knife/cookbook_metadata_from_file.rb +4 -0
  55. data/lib/chef/knife/cookbook_show.rb +16 -5
  56. data/lib/chef/knife/cookbook_site_download.rb +2 -2
  57. data/lib/chef/knife/cookbook_site_share.rb +18 -13
  58. data/lib/chef/knife/cookbook_site_unshare.rb +7 -4
  59. data/lib/chef/knife/cookbook_site_vendor.rb +21 -18
  60. data/lib/chef/knife/cookbook_test.rb +14 -14
  61. data/lib/chef/knife/cookbook_upload.rb +91 -40
  62. data/lib/chef/knife/data_bag_create.rb +41 -6
  63. data/lib/chef/knife/data_bag_delete.rb +5 -3
  64. data/lib/chef/knife/data_bag_edit.rb +55 -11
  65. data/lib/chef/knife/data_bag_from_file.rb +47 -7
  66. data/lib/chef/knife/data_bag_list.rb +4 -1
  67. data/lib/chef/knife/data_bag_show.rb +44 -4
  68. data/lib/chef/knife/environment_create.rb +53 -0
  69. data/lib/chef/knife/environment_delete.rb +45 -0
  70. data/lib/chef/knife/environment_edit.rb +45 -0
  71. data/lib/chef/knife/environment_from_file.rb +39 -0
  72. data/lib/chef/knife/environment_list.rb +42 -0
  73. data/lib/chef/knife/environment_show.rb +46 -0
  74. data/lib/chef/knife/exec.rb +1 -1
  75. data/lib/chef/knife/index_rebuild.rb +8 -9
  76. data/lib/chef/knife/node_bulk_delete.rb +9 -6
  77. data/lib/chef/knife/node_create.rb +9 -6
  78. data/lib/chef/knife/node_delete.rb +10 -7
  79. data/lib/chef/knife/node_edit.rb +129 -10
  80. data/lib/chef/knife/node_from_file.rb +10 -7
  81. data/lib/chef/knife/node_list.rb +11 -6
  82. data/lib/chef/knife/node_run_list_add.rb +10 -7
  83. data/lib/chef/knife/node_run_list_remove.rb +9 -6
  84. data/lib/chef/knife/node_show.rb +15 -7
  85. data/lib/chef/knife/recipe_list.rb +4 -3
  86. data/lib/chef/knife/role_bulk_delete.rb +9 -6
  87. data/lib/chef/knife/role_create.rb +9 -6
  88. data/lib/chef/knife/role_delete.rb +10 -7
  89. data/lib/chef/knife/role_edit.rb +11 -8
  90. data/lib/chef/knife/role_from_file.rb +10 -7
  91. data/lib/chef/knife/role_list.rb +8 -5
  92. data/lib/chef/knife/role_show.rb +11 -8
  93. data/lib/chef/knife/search.rb +33 -10
  94. data/lib/chef/knife/ssh.rb +33 -61
  95. data/lib/chef/knife/status.rb +7 -4
  96. data/lib/chef/knife/subcommand_loader.rb +101 -0
  97. data/lib/chef/knife/tag_create.rb +31 -0
  98. data/lib/chef/knife/tag_delete.rb +31 -0
  99. data/lib/chef/knife/tag_list.rb +29 -0
  100. data/lib/chef/knife/ui.rb +229 -0
  101. data/lib/chef/knife/windows_bootstrap.rb +8 -5
  102. data/lib/chef/log.rb +5 -59
  103. data/lib/chef/mash.rb +211 -0
  104. data/lib/chef/mixins.rb +1 -2
  105. data/lib/chef/nil_argument.rb +3 -0
  106. data/lib/chef/node.rb +96 -34
  107. data/lib/chef/platform.rb +27 -0
  108. data/lib/chef/provider/cookbook_file.rb +21 -20
  109. data/lib/chef/provider/deploy/revision.rb +3 -0
  110. data/lib/chef/provider/file.rb +20 -11
  111. data/lib/chef/provider/git.rb +26 -26
  112. data/lib/chef/provider/group/aix.rb +70 -0
  113. data/lib/chef/provider/group/groupadd.rb +7 -4
  114. data/lib/chef/provider/group/usermod.rb +1 -1
  115. data/lib/chef/provider/package.rb +28 -28
  116. data/lib/chef/provider/package/dpkg.rb +1 -1
  117. data/lib/chef/provider/package/portage.rb +50 -39
  118. data/lib/chef/provider/package/rubygems.rb +1 -1
  119. data/lib/chef/provider/package/zypper.rb +3 -20
  120. data/lib/chef/provider/remote_directory.rb +0 -2
  121. data/lib/chef/provider/remote_file.rb +2 -3
  122. data/lib/chef/provider/service/arch.rb +28 -35
  123. data/lib/chef/provider/service/simple.rb +1 -1
  124. data/lib/chef/provider/subversion.rb +22 -22
  125. data/lib/chef/providers.rb +1 -0
  126. data/lib/chef/recipe.rb +10 -12
  127. data/lib/chef/resource.rb +49 -42
  128. data/lib/chef/resource/gem_package.rb +7 -3
  129. data/lib/chef/resource/git.rb +5 -5
  130. data/lib/chef/resource/package.rb +7 -7
  131. data/lib/chef/resource/scm.rb +2 -1
  132. data/lib/chef/resource/solaris_package.rb +0 -1
  133. data/lib/chef/resource/yum_package.rb +0 -1
  134. data/lib/chef/rest.rb +7 -16
  135. data/lib/chef/rest/rest_request.rb +0 -16
  136. data/lib/chef/role.rb +67 -13
  137. data/lib/chef/run_context.rb +37 -21
  138. data/lib/chef/run_list.rb +30 -15
  139. data/lib/chef/run_list/run_list_expansion.rb +41 -20
  140. data/lib/chef/run_list/run_list_item.rb +20 -6
  141. data/lib/chef/run_list/versioned_recipe_list.rb +68 -0
  142. data/lib/chef/runner.rb +7 -15
  143. data/lib/chef/search/query.rb +12 -7
  144. data/lib/chef/shef.rb +6 -7
  145. data/lib/chef/shef/shef_session.rb +40 -35
  146. data/lib/chef/shell_out.rb +22 -201
  147. data/lib/chef/shell_out/unix.rb +224 -0
  148. data/lib/chef/shell_out/windows.rb +95 -0
  149. data/lib/chef/solr_query.rb +187 -0
  150. data/lib/chef/solr_query/lucene.treetop +145 -0
  151. data/lib/chef/solr_query/lucene_nodes.rb +285 -0
  152. data/lib/chef/solr_query/query_transform.rb +65 -0
  153. data/lib/chef/solr_query/solr_http_request.rb +118 -0
  154. data/lib/chef/version.rb +4 -2
  155. data/lib/chef/version_class.rb +70 -0
  156. data/lib/chef/version_constraint.rb +116 -0
  157. metadata +68 -37
  158. data/lib/chef/cookbook/metadata/version.rb +0 -87
  159. data/lib/chef/knife/bluebox_images_list.rb +0 -54
  160. data/lib/chef/knife/bluebox_server_create.rb +0 -157
  161. data/lib/chef/knife/bluebox_server_delete.rb +0 -63
  162. data/lib/chef/knife/bluebox_server_list.rb +0 -59
  163. data/lib/chef/knife/ec2_instance_data.rb +0 -46
  164. data/lib/chef/knife/ec2_server_create.rb +0 -218
  165. data/lib/chef/knife/ec2_server_delete.rb +0 -87
  166. data/lib/chef/knife/ec2_server_list.rb +0 -89
  167. data/lib/chef/knife/rackspace_server_create.rb +0 -184
  168. data/lib/chef/knife/rackspace_server_delete.rb +0 -57
  169. data/lib/chef/knife/rackspace_server_list.rb +0 -59
  170. data/lib/chef/knife/slicehost_images_list.rb +0 -53
  171. data/lib/chef/knife/slicehost_server_create.rb +0 -103
  172. data/lib/chef/knife/slicehost_server_delete.rb +0 -61
  173. data/lib/chef/knife/slicehost_server_list.rb +0 -64
  174. data/lib/chef/knife/terremark_server_create.rb +0 -152
  175. data/lib/chef/knife/terremark_server_delete.rb +0 -87
  176. data/lib/chef/knife/terremark_server_list.rb +0 -77
  177. data/lib/chef/mixin/find_preferred_file.rb +0 -92
@@ -0,0 +1,31 @@
1
+ require 'chef/knife'
2
+
3
+ class Chef
4
+ class Knife
5
+ class TagCreate < Knife
6
+
7
+ deps do
8
+ require 'chef/node'
9
+ end
10
+
11
+ banner "knife tag create NODE TAG ..."
12
+
13
+ def run
14
+ name = @name_args[0]
15
+ tags = @name_args[1..-1].join(",").split(/\s*,\s*/)
16
+
17
+ unless name or tags.empty?
18
+ show_usage
19
+ # TODO: blah blah
20
+ ui.fatal("You must specify a node name")
21
+ exit 1
22
+ end
23
+
24
+ node = Chef::Node.load name
25
+ tags.each do |tag|
26
+ node.tags << tag
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require 'chef/knife'
2
+
3
+ class Chef
4
+ class Knife
5
+ class TagDelete < Knife
6
+
7
+ deps do
8
+ require 'chef/node'
9
+ end
10
+
11
+ banner "knife tag delete NODE TAG ..."
12
+
13
+ def run
14
+ name = @name_args[0]
15
+ tags = @name_args[1..-1].join(",").split(/\s*,\s*/)
16
+
17
+ unless name or tags.empty?
18
+ show_usage
19
+ # TODO: blah blah
20
+ ui.fatal("You must specify a node name")
21
+ exit 1
22
+ end
23
+
24
+ node = Chef::Node.load name
25
+ tags.each do |tag|
26
+ node.tags.delete tag
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ require 'chef/knife'
2
+
3
+ class Chef
4
+ class Knife
5
+ class TagList < Knife
6
+
7
+ deps do
8
+ require 'chef/node'
9
+ end
10
+
11
+ banner "knife tag list NODE"
12
+
13
+ def run
14
+ name = @name_args[0]
15
+ tags = @name_args[1..-1].join(",").split(/\s*,\s*/)
16
+
17
+ unless name or tags.empty?
18
+ show_usage
19
+ # TODO: blah blah
20
+ ui.fatal("You must specify a node name")
21
+ exit 1
22
+ end
23
+
24
+ node = Chef::Node.load name
25
+ output node.tags
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,229 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Christopher Brown (<cb@opscode.com>)
4
+ # Author:: Daniel DeLeo (<dan@opscode.com>)
5
+ # Copyright:: Copyright (c) 2009, 2011 Opscode, Inc.
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+
22
+ class Chef
23
+ class Knife
24
+ class UI
25
+
26
+ attr_reader :stdout
27
+ attr_reader :stderr
28
+ attr_reader :stdin
29
+ attr_reader :config
30
+
31
+ def initialize(stdout, stderr, stdin, config)
32
+ @stdout, @stderr, @stdin, @config = stdout, stderr, stdin, config
33
+ end
34
+
35
+ def highline
36
+ @highline ||= begin
37
+ require 'highline'
38
+ HighLine.new
39
+ end
40
+ end
41
+
42
+ def msg(message)
43
+ stdout.puts message
44
+ end
45
+
46
+ alias :info :msg
47
+
48
+ def warn(message)
49
+ msg("WARNING: #{message}")
50
+ end
51
+
52
+ def error(message)
53
+ msg("ERROR: #{message}")
54
+ end
55
+
56
+ def fatal(message)
57
+ msg("FATAL: #{message}")
58
+ end
59
+
60
+ def color(*args)
61
+ highline.color(*args)
62
+ end
63
+
64
+ def ask(*args, &block)
65
+ highline.ask(*args, &block)
66
+ end
67
+
68
+ def list(*args)
69
+ highline.list(*args)
70
+ end
71
+
72
+ def ask_question(question, opts={})
73
+ question = question + "[#{opts[:default]}] " if opts[:default]
74
+
75
+ if opts[:default] and config[:defaults]
76
+ opts[:default]
77
+ else
78
+ stdout.print question
79
+ a = stdin.readline.strip
80
+
81
+ if opts[:default]
82
+ a.empty? ? opts[:default] : a
83
+ else
84
+ a
85
+ end
86
+ end
87
+ end
88
+
89
+ def pretty_print(data)
90
+ stdout.puts data
91
+ end
92
+
93
+ def output(data)
94
+ case config[:format]
95
+ when "json", nil
96
+ stdout.puts Chef::JSONCompat.to_json_pretty(data)
97
+ when "yaml"
98
+ require 'yaml'
99
+ stdout.puts YAML::dump(data)
100
+ when "text"
101
+ # If you were looking for some attribute and there is only one match
102
+ # just dump the attribute value
103
+ if data.length == 1 and config[:attribute]
104
+ stdout.puts data.values[0]
105
+ else
106
+ PP.pp(data, stdout)
107
+ end
108
+ else
109
+ raise ArgumentError, "Unknown output format #{config[:format]}"
110
+ end
111
+ end
112
+
113
+ def format_list_for_display(list)
114
+ config[:with_uri] ? list : list.keys.sort { |a,b| a <=> b }
115
+ end
116
+
117
+ def format_for_display(item)
118
+ data = item.kind_of?(Chef::DataBagItem) ? item.raw_data : item
119
+
120
+ if config[:attribute]
121
+ config[:attribute].split(".").each do |attr|
122
+ if data.respond_to?(:[])
123
+ data = data[attr]
124
+ elsif data.nil?
125
+ nil # don't get no method error on nil
126
+ else data.respond_to?(attr.to_sym)
127
+ data = data.send(attr.to_sym)
128
+ end
129
+ end
130
+ { config[:attribute] => data.kind_of?(Chef::Node::Attribute) ? data.to_hash : data }
131
+ elsif config[:run_list]
132
+ data = data.run_list.run_list
133
+ { "run_list" => data }
134
+ elsif config[:environment]
135
+ if data.class == Chef::Node
136
+ {"chef_environment" => data.chef_environment}
137
+ else
138
+ # this is a place holder for now. Feel free to modify (i.e. add other cases). [nuo]
139
+ data
140
+ end
141
+ elsif config[:id_only]
142
+ data.respond_to?(:name) ? data.name : data["id"]
143
+ else
144
+ data
145
+ end
146
+ end
147
+
148
+ def format_cookbook_list_for_display(item)
149
+ if config[:with_uri]
150
+ item
151
+ else
152
+ item.inject({}){|result, (k,v)|
153
+ result[k] = v["versions"].inject([]){|res, ver| res.push(ver["version"]); res}
154
+ result
155
+ }
156
+ end
157
+ end
158
+
159
+ def edit_data(data, parse_output=true)
160
+ output = Chef::JSONCompat.to_json_pretty(data)
161
+
162
+ if (!config[:no_editor])
163
+ filename = "knife-edit-"
164
+ 0.upto(20) { filename += rand(9).to_s }
165
+ filename << ".js"
166
+ filename = File.join(Dir.tmpdir, filename)
167
+ tf = File.open(filename, "w")
168
+ tf.sync = true
169
+ tf.puts output
170
+ tf.close
171
+ raise "Please set EDITOR environment variable" unless system("#{config[:editor]} #{tf.path}")
172
+ tf = File.open(filename, "r")
173
+ output = tf.gets(nil)
174
+ tf.close
175
+ File.unlink(filename)
176
+ end
177
+
178
+ parse_output ? Chef::JSONCompat.from_json(output) : output
179
+ end
180
+
181
+ def edit_object(klass, name)
182
+ object = klass.load(name)
183
+
184
+ output = edit_data(object)
185
+
186
+ # Only make the save if the user changed the object.
187
+ #
188
+ # Output JSON for the original (object) and edited (output), then parse
189
+ # them without reconstituting the objects into real classes
190
+ # (create_additions=false). Then, compare the resulting simple objects,
191
+ # which will be Array/Hash/String/etc.
192
+ #
193
+ # We wouldn't have to do these shenanigans if all the editable objects
194
+ # implemented to_hash, or if to_json against a hash returned a string
195
+ # with stable key order.
196
+ object_parsed_again = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(object), :create_additions => false)
197
+ output_parsed_again = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(output), :create_additions => false)
198
+ if object_parsed_again != output_parsed_again
199
+ output.save
200
+ self.msg("Saved #{output}")
201
+ else
202
+ self.msg("Object unchanged, not saving")
203
+ end
204
+ output(format_for_display(object)) if config[:print_after]
205
+ end
206
+
207
+ def confirm(question, append_instructions=true)
208
+ return true if config[:yes]
209
+
210
+ stdout.print question
211
+ stdout.print "? (Y/N) " if append_instructions
212
+ answer = stdin.readline
213
+ answer.chomp!
214
+ case answer
215
+ when "Y", "y"
216
+ true
217
+ when "N", "n"
218
+ self.msg("You said no, so I'm done here.")
219
+ exit 3
220
+ else
221
+ self.msg("I have no idea what to do with #{answer}")
222
+ self.msg("Just say Y or N, please.")
223
+ confirm(question)
224
+ end
225
+ end
226
+
227
+ end
228
+ end
229
+ end
@@ -17,12 +17,15 @@
17
17
  #
18
18
 
19
19
  require 'fileutils'
20
- require 'chef/knife/bootstrap.rb'
21
20
 
22
21
  class Chef
23
22
  class Knife
24
23
  class WindowsBootstrap < Chef::Knife::Bootstrap
25
24
 
25
+ deps do
26
+ require 'chef/knife/bootstrap.rb'
27
+ end
28
+
26
29
  banner "knife windows bootstrap FQDN [RUN LIST...] (options)"
27
30
 
28
31
  option :user,
@@ -76,9 +79,9 @@ class Chef
76
79
  }
77
80
  @net_use.add(use)
78
81
  if is_mounted
79
- Chef::Log.info("Mounted #{@admin_share} for copying files")
82
+ ui.info("Mounted #{@admin_share} for copying files")
80
83
  else
81
- Chef::Log.fatal("Failed to mount #{@admin_share}")
84
+ ui.fatal("Failed to mount #{@admin_share}")
82
85
  exit 1
83
86
  end
84
87
  end
@@ -109,7 +112,7 @@ class Chef
109
112
  require 'chef/util/windows/net_use'
110
113
 
111
114
  if @name_args.first == nil
112
- Chef::Log.error("Must pass a node name/ip to windows bootstrap")
115
+ ui.error("Must pass a node name/ip to windows bootstrap")
113
116
  exit 1
114
117
  end
115
118
 
@@ -129,7 +132,7 @@ class Chef
129
132
 
130
133
  command = render_template(load_template(config[:bootstrap_template]))
131
134
 
132
- Chef::Log.info("Bootstrapping Chef on #{config[:server_name]}")
135
+ ui.info("Bootstrapping Chef on #{config[:server_name]}")
133
136
 
134
137
  @add_mount = config[:user] != nil && !is_mounted
135
138
  mount_admin_share
@@ -8,9 +8,9 @@
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
9
9
  # you may not use this file except in compliance with the License.
10
10
  # You may obtain a copy of the License at
11
- #
11
+ #
12
12
  # http://www.apache.org/licenses/LICENSE-2.0
13
- #
13
+ #
14
14
  # Unless required by applicable law or agreed to in writing, software
15
15
  # distributed under the License is distributed on an "AS IS" BASIS,
16
16
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,71 +23,17 @@ require 'mixlib/log'
23
23
  class Chef
24
24
  class Log
25
25
  extend Mixlib::Log
26
-
27
- class << self
28
- attr_reader :verbose_logger
29
-
30
- @verbose_logger = nil
31
- @verbose = false
32
-
33
- def verbose?
34
- @verbose
35
- end
36
-
37
- alias :verbose :verbose?
38
-
39
- def verbose=(value)
40
- if value
41
- @verbose = true
42
- @verbose_logger ||= Logger.new(STDOUT)
43
- @verbose_logger.level = self.logger.level
44
- @verbose_logger.formatter = self.logger.formatter
45
- else
46
- @verbose, @verbose_logger = false, nil
47
- end
48
- self.verbose
49
- end
50
-
51
- [:debug, :info, :warn, :error, :fatal].each do |method_name|
52
- class_eval(<<-METHOD_DEFN, __FILE__, __LINE__)
53
- def #{method_name}(msg=nil, &block)
54
- @logger.#{method_name}(msg, &block)
55
- @verbose_logger.#{method_name}(msg, &block) if verbose?
56
- end
57
- METHOD_DEFN
58
- end
59
26
 
60
- [:debug?, :info?, :warn?, :error?, :fatal?].each do |method_name|
61
- class_eval(<<-METHOD_DEFN, __FILE__, __LINE__)
62
- def #{method_name}
63
- @logger.#{method_name}
64
- end
65
- METHOD_DEFN
66
- end
67
-
68
- def <<(msg)
69
- @logger << msg
70
- end
71
-
72
- def add(severity, message = nil, progname = nil, &block)
73
- @logger.add(severity, message = nil, progname = nil, &block)
74
- end
75
-
76
- end
77
-
78
- # NOTE: Mixlib::Log initially sets @logger to nil and depends on
79
- # #init being called to initialize the logger. We don't want to
80
- # incur extra method call overhead for every log message so we're
81
- # accessing the logger by instance variable, which means we need to
82
- # make Mixlib::Log initialize it.
27
+ # Force initialization of the primary log device (@logger)
83
28
  init
84
29
 
30
+
85
31
  class Formatter
86
32
  def self.show_time=(*args)
87
33
  Mixlib::Log::Formatter.show_time = *args
88
34
  end
89
35
  end
90
-
36
+
91
37
  end
92
38
  end
93
39