user2250246 user2250246 - 3 months ago 9
Ruby Question

What does the name of the resource block represent in chef's log construct?

I am confused by the description of the 'name' element in chef docs.
Example code:

log 'message' do
message 'This is the message that will be added to the log.'
level :info
end


Why does message appear twice above?

What does it mean during each occurrence?

Answer

I think the doc just chose the resource block's name a little injudiciously. A better example might be:

log 'foo' do
    message 'Logging to foo'
    level :fatal
end

In this case, the log resource's name is 'foo', while the message argument dictates what message to log. If the message argument is left empty, it defaults to the value of name (in this case, 'foo'). So, in this case:

log 'foo' do
    level :fatal
end

The literal text foo would get dumped to your logfile.