Logging within a ruby_block

I have searched the interwebs and have not found the answer that I am
looking for so hopefully someone where has solved my problem

I want to log stuff using chef log levels when inside a ruby_block. The
BELOW DOES NOT WORK

ruby_block “ruby_block_thing” do
block do
foo = my_method
if foo.sucess?
Chef::Log.info(“sucessfully ran my_method”)
Chef::Log.debug(“my_method said #{foo.response}”)
end
end
action :run
end

Any know the “correct” way to log stuff within a ruby block. I am hoping
that using puts is not the best answer.

As you can see here I want to output different thing based on different log
level.

:info and :debug are suppressed by default, if you do 'chef-client -l
info' do you see your log message?

On 3/6/15 12:07 PM, Mark Selby wrote:

I have searched the interwebs and have not found the answer that I am
looking for so hopefully someone where has solved my problem

I want to log stuff using chef log levels when inside a ruby_block.
The BELOW DOES NOT WORK

ruby_block "ruby_block_thing" do
block do
foo = my_method
if foo.sucess?
Chef::Log.info("sucessfully ran my_method")
Chef::Log.debug("my_method said #{foo.response}")
end
end
action :run
end

Any know the "correct" way to log stuff within a ruby block. I am
hoping that using puts is not the best answer.

As you can see here I want to output different thing based on
different log level.

I can confirm that running chef-client with -l info or -l debug still does
not produce the requested logs. I am pretty sure that I have to do
somethint special to get logging inside a ruby_block to work

On Fri, Mar 6, 2015 at 12:10 PM, Lamont Granquist lamont@chef.io wrote:

:info and :debug are suppressed by default, if you do 'chef-client -l
info' do you see your log message?

On 3/6/15 12:07 PM, Mark Selby wrote:

I have searched the interwebs and have not found the answer that I am
looking for so hopefully someone where has solved my problem

I want to log stuff using chef log levels when inside a ruby_block. The
BELOW DOES NOT WORK

ruby_block "ruby_block_thing" do
block do
foo = my_method
if foo.sucess?
Chef::Log.info("sucessfully ran my_method")
Chef::Log.debug("my_method said #{foo.response}")
end
end
action :run
end

Any know the "correct" way to log stuff within a ruby block. I am hoping
that using puts is not the best answer.

As you can see here I want to output different thing based on different
log level.

Can you see the logs if you put them outside the if foo.success? block?

Chris

From: Mark Selby [mailto:mselby@thenextbigsound.com]
Sent: Friday, March 06, 2015 3:27 PM
To: Lamont Granquist
Cc: chef@lists.opscode.com
Subject: [chef] Re: Logging within a ruby_block

I can confirm that running chef-client with -l info or -l debug still does not produce the requested logs. I am pretty sure that I have to do somethint special to get logging inside a ruby_block to work

On Fri, Mar 6, 2015 at 12:10 PM, Lamont Granquist <lamont@chef.iomailto:lamont@chef.io> wrote:
:info and :debug are suppressed by default, if you do ‘chef-client -l info’ do you see your log message?

On 3/6/15 12:07 PM, Mark Selby wrote:
I have searched the interwebs and have not found the answer that I am looking for so hopefully someone where has solved my problem

I want to log stuff using chef log levels when inside a ruby_block. The BELOW DOES NOT WORK

ruby_block “ruby_block_thing” do
block do
foo = my_method
if foo.sucess?
Chef::Log.info(“sucessfully ran my_method”)
Chef::Log.debug(“my_method said #{foo.response}”)
end
end
action :run
end

Any know the “correct” way to log stuff within a ruby block. I am hoping that using puts is not the best answer.

As you can see here I want to output different thing based on different log level.

--force-loggger.

On Fri, Mar 6, 2015 at 12:26 PM, Mark Selby mselby@thenextbigsound.com
wrote:

I can confirm that running chef-client with -l info or -l debug still does
not produce the requested logs. I am pretty sure that I have to do
somethint special to get logging inside a ruby_block to work

On Fri, Mar 6, 2015 at 12:10 PM, Lamont Granquist lamont@chef.io wrote:

:info and :debug are suppressed by default, if you do 'chef-client -l
info' do you see your log message?

On 3/6/15 12:07 PM, Mark Selby wrote:

I have searched the interwebs and have not found the answer that I am
looking for so hopefully someone where has solved my problem

I want to log stuff using chef log levels when inside a ruby_block. The
BELOW DOES NOT WORK

ruby_block "ruby_block_thing" do
block do
foo = my_method
if foo.sucess?
Chef::Log.info("sucessfully ran my_method")
Chef::Log.debug("my_method said #{foo.response}")
end
end
action :run
end

Any know the "correct" way to log stuff within a ruby block. I am
hoping that using puts is not the best answer.

As you can see here I want to output different thing based on different
log level.

Are you saying that the only way to log within a ruby block is to use
--force-logger on the command line which completely changes the output of
the entire chef run?

On Fri, Mar 6, 2015 at 12:37 PM, Ranjib Dey dey.ranjib@gmail.com wrote:

--force-loggger.

On Fri, Mar 6, 2015 at 12:26 PM, Mark Selby mselby@thenextbigsound.com
wrote:

I can confirm that running chef-client with -l info or -l debug still
does not produce the requested logs. I am pretty sure that I have to do
somethint special to get logging inside a ruby_block to work

On Fri, Mar 6, 2015 at 12:10 PM, Lamont Granquist lamont@chef.io wrote:

:info and :debug are suppressed by default, if you do 'chef-client -l
info' do you see your log message?

On 3/6/15 12:07 PM, Mark Selby wrote:

I have searched the interwebs and have not found the answer that I am
looking for so hopefully someone where has solved my problem

I want to log stuff using chef log levels when inside a ruby_block.
The BELOW DOES NOT WORK

ruby_block "ruby_block_thing" do
block do
foo = my_method
if foo.sucess?
Chef::Log.info("sucessfully ran my_method")
Chef::Log.debug("my_method said #{foo.response}")
end
end
action :run
end

Any know the "correct" way to log stuff within a ruby block. I am
hoping that using puts is not the best answer.

As you can see here I want to output different thing based on
different log level.