Logging and references questions

Hi there,

I have problems with understanding the logging procedure with chef.

I can log some information by using the following syntax:
log „foo" do
level :debug
end

Now I find in some cookbooks the following spelling:
Chef::Log.debug("Node has Chef Server Recipe? #{node.recipe?(“chef-server”)}“)

What does Chef::Log.debug exactly do?
I do not get any output if i run the chef-client in normal or in debug mode. What is the STDOUT from Chef::Log?

By the way, I am not really sure what Chef:: represents. Where can I find the class or module Chef?
In some scripts I the other references like Chef::Client::SANE_PATHS. Where can I find the content of such references?

Sorry if the questions are a litte bit stupid, but I am right new in writing Code.

Thank you very much,

Christian

On Wednesday, April 16, 2014 at 4:16 AM, Christian Fröstl wrote:

Hi there,

I have problems with understanding the logging procedure with chef.

I can log some information by using the following syntax:
log „foo" do
level :debug
end

Now I find in some cookbooks the following spelling:
Chef::Log.debug("Node has Chef Server Recipe? #{node.recipe?("chef-server")}“)

This blog post is a pretty awesome and thorough description of how chef-client has two stages: compile and converge: http://erik.hollensbe.org/2013/03/16/the-chef-resource-run-queue/

Chef::Log.debug is a method call that writes a string to the logger, which then writes it do some device (or not, depending on your log level, etc.). The log resource puts an item in the resource_collection queue. In the converge phase chef iterates over this queue, and will eventually run this code https://github.com/opscode/chef/blob/master/lib/chef/provider/log.rb which you can see is more or less the same as Chef::Log.debug(). So the primary difference is the timing.

What does Chef::Log.debug exactly do?
I do not get any output if i run the chef-client in normal or in debug mode. What is the STDOUT from Chef::Log?

Did you configure chef to log to a file? Check your client.rb.

By the way, I am not really sure what Chef:: represents. Where can I find the class or module Chef?
In some scripts I the other references like Chef::Client::SANE_PATHS. Where can I find the content of such references?

Sorry if the questions are a litte bit stupid, but I am right new in writing Code.
One easy way to spelunk the code is to clone the git repo from here: GitHub - chef/chef: Chef Infra, a powerful automation platform that transforms infrastructure into code automating how infrastructure is configured, deployed and managed across any environment, at any scale and use git grep to search the codebase.

Thank you very much,

Christian
HTH,

--
Daniel DeLeo

Hi there,

I just loaded the Cookbook from juliandunn to get some output with the
chef_handler. My code looks like the following:

Handler:
require 'chef/log'

module Opscode
class CookbookVersionsHandler < Chef::Handler

def report
  cookbooks = run_context.cookbook_collection
Chef::Log.debug("Cookbooks and versions run: #{cookbooks.keys.map {|x|

cookbooks.name.to_s + " " + cookbooks.version} }")
end
end
End

Recipe:
chef_handler "Opscode::CookbookVersionsHandler" do
source "#{node["chef_handler"]["handler_path"]}/chf.rb"
supports :report => true
action :enable
End

At the end of the client run, the Handler will run, too. But I don’t get
some output:

Running handlers:

  • Opscode::CookbookVersionsHandler
    Running handlers complete

Chef Client finished, 4/117 resources updated in 20.13747256 seconds

How can I debug the missing Chef::Log message?

Thanks,
Christian

Am 16.04.14 20:25 schrieb "Daniel DeLeo" unter dan@kallistec.com:

On Wednesday, April 16, 2014 at 4:16 AM, Christian Fröstl wrote:

Hi there,

I have problems with understanding the logging procedure with chef.

I can log some information by using the following syntax:
log „foo" do
level :debug
end

Now I find in some cookbooks the following spelling:
Chef::Log.debug("Node has Chef Server Recipe?
#{node.recipe?("chef-server")}“)

This blog post is a pretty awesome and thorough description of how
chef-client has two stages: compile and converge:
http://erik.hollensbe.org/2013/03/16/the-chef-resource-run-queue/

Chef::Log.debug is a method call that writes a string to the logger,
which then writes it do some device (or not, depending on your log level,
etc.). The log resource puts an item in the resource_collection queue. In
the converge phase chef iterates over this queue, and will eventually run
this code
https://github.com/opscode/chef/blob/master/lib/chef/provider/log.rb
which you can see is more or less the same as Chef::Log.debug(). So the
primary difference is the timing.

What does Chef::Log.debug exactly do?
I do not get any output if i run the chef-client in normal or in debug
mode. What is the STDOUT from Chef::Log?

Did you configure chef to log to a file? Check your client.rb.

By the way, I am not really sure what Chef:: represents. Where can I
find the class or module Chef?
In some scripts I the other references like Chef::Client::SANE_PATHS.
Where can I find the content of such references?

Sorry if the questions are a litte bit stupid, but I am right new in
writing Code.
One easy way to spelunk the code is to clone the git repo from here:
GitHub - chef/chef: Chef Infra, a powerful automation platform that transforms infrastructure into code automating how infrastructure is configured, deployed and managed across any environment, at any scale and use git grep to search the codebase.

Thank you very much,

Christian
HTH,

--
Daniel DeLeo

Ohai, this is the author here... :slight_smile:

Since it's logging at debug level you'll need -l debug.

Actually, this handler is obsolete if you are on Chef 11.12.x, which
prints the cookbook versions as part of the beginning of the run:

$ sudo chef-client --force-logger
[2014-04-17T12:50:59-04:00] INFO: *** Chef 11.12.2 ***
[2014-04-17T12:50:59-04:00] INFO: Chef-client pid: 10233
[2014-04-17T12:51:01-04:00] INFO: Run List is [role[base-linux], role[fedora]]
[2014-04-17T12:51:01-04:00] INFO: Run List expands to
[selinux::permissive, users::sysadmins, sudo, chef-client::config,
chef-client::service, chef-client::delete_validation, ntp, stdutils,
yum, yum-fedora]
[2014-04-17T12:51:01-04:00] INFO: Starting Chef Run for [deleted]
[2014-04-17T12:51:01-04:00] INFO: Running start handlers
[2014-04-17T12:51:01-04:00] INFO: Start handlers complete.
[2014-04-17T12:51:02-04:00] INFO: Loading cookbooks [selinux@0.6.2,
users@1.6.0, sudo@2.2.2, chef-client@3.4.0, cron@1.2.8,
logrotate@1.4.0, ntp@1.5.0, stdutils@1.0.2, yum@3.0.4,
yum-fedora@0.1.4]

regards,
Julian

On Wed, Apr 23, 2014 at 4:48 AM, Christian Fröstl
christian.froestl@nubon.com wrote:

Hi there,

I just loaded the Cookbook from juliandunn to get some output with the
chef_handler. My code looks like the following:

Handler:
require 'chef/log'

module Opscode
class CookbookVersionsHandler < Chef::Handler

def report
  cookbooks = run_context.cookbook_collection
    Chef::Log.debug("Cookbooks and versions run: #{cookbooks.keys.map {|x|

cookbooks.name.to_s + " " + cookbooks.version} }")
end
end
End

Recipe:
chef_handler "Opscode::CookbookVersionsHandler" do
source "#{node["chef_handler"]["handler_path"]}/chf.rb"
supports :report => true
action :enable
End

At the end of the client run, the Handler will run, too. But I don’t get
some output:

Running handlers:

  • Opscode::CookbookVersionsHandler
    Running handlers complete

Chef Client finished, 4/117 resources updated in 20.13747256 seconds

How can I debug the missing Chef::Log message?

Thanks,
Christian

Am 16.04.14 20:25 schrieb "Daniel DeLeo" unter dan@kallistec.com:

On Wednesday, April 16, 2014 at 4:16 AM, Christian Fröstl wrote:

Hi there,

I have problems with understanding the logging procedure with chef.

I can log some information by using the following syntax:
log „foo" do
level :debug
end

Now I find in some cookbooks the following spelling:
Chef::Log.debug("Node has Chef Server Recipe?
#{node.recipe?("chef-server")}“)

This blog post is a pretty awesome and thorough description of how
chef-client has two stages: compile and converge:
http://erik.hollensbe.org/2013/03/16/the-chef-resource-run-queue/

Chef::Log.debug is a method call that writes a string to the logger,
which then writes it do some device (or not, depending on your log level,
etc.). The log resource puts an item in the resource_collection queue. In
the converge phase chef iterates over this queue, and will eventually run
this code
https://github.com/opscode/chef/blob/master/lib/chef/provider/log.rb
which you can see is more or less the same as Chef::Log.debug(). So the
primary difference is the timing.

What does Chef::Log.debug exactly do?
I do not get any output if i run the chef-client in normal or in debug
mode. What is the STDOUT from Chef::Log?

Did you configure chef to log to a file? Check your client.rb.

By the way, I am not really sure what Chef:: represents. Where can I
find the class or module Chef?
In some scripts I the other references like Chef::Client::SANE_PATHS.
Where can I find the content of such references?

Sorry if the questions are a litte bit stupid, but I am right new in
writing Code.
One easy way to spelunk the code is to clone the git repo from here:
GitHub - chef/chef: Chef Infra, a powerful automation platform that transforms infrastructure into code automating how infrastructure is configured, deployed and managed across any environment, at any scale and use git grep to search the codebase.

Thank you very much,

Christian
HTH,

--
Daniel DeLeo

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: http://www.aquezada.com/staff/julian * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

I've been finding that if I have a log level in chef-client.rb, it
overrides the level I set on the command line. Is that intentional? Is
there a rationale for that?

--
Cameron Cope | Systems Engineer
Brightcove, Inc
290 Congress Street, 4th Floor, Boston, MA 02110
ccope@brightcove.com
On Apr 23, 2014 9:47 AM, "Julian C. Dunn" jdunn@aquezada.com wrote:

Ohai, this is the author here... :slight_smile:

Since it's logging at debug level you'll need -l debug.

Actually, this handler is obsolete if you are on Chef 11.12.x, which
prints the cookbook versions as part of the beginning of the run:

$ sudo chef-client --force-logger
[2014-04-17T12:50:59-04:00] INFO: *** Chef 11.12.2 ***
[2014-04-17T12:50:59-04:00] INFO: Chef-client pid: 10233
[2014-04-17T12:51:01-04:00] INFO: Run List is [role[base-linux],
role[fedora]]
[2014-04-17T12:51:01-04:00] INFO: Run List expands to
[selinux::permissive, users::sysadmins, sudo, chef-client::config,
chef-client::service, chef-client::delete_validation, ntp, stdutils,
yum, yum-fedora]
[2014-04-17T12:51:01-04:00] INFO: Starting Chef Run for [deleted]
[2014-04-17T12:51:01-04:00] INFO: Running start handlers
[2014-04-17T12:51:01-04:00] INFO: Start handlers complete.
[2014-04-17T12:51:02-04:00] INFO: Loading cookbooks [selinux@0.6.2,
users@1.6.0, sudo@2.2.2, chef-client@3.4.0, cron@1.2.8,
logrotate@1.4.0, ntp@1.5.0, stdutils@1.0.2, yum@3.0.4,
yum-fedora@0.1.4]

regards,
Julian

On Wed, Apr 23, 2014 at 4:48 AM, Christian Fröstl
christian.froestl@nubon.com wrote:

Hi there,

I just loaded the Cookbook from juliandunn to get some output with the
chef_handler. My code looks like the following:

Handler:
require 'chef/log'

module Opscode
class CookbookVersionsHandler < Chef::Handler

def report
  cookbooks = run_context.cookbook_collection
    Chef::Log.debug("Cookbooks and versions run:

#{cookbooks.keys.map {|x|

cookbooks.name.to_s + " " + cookbooks.version} }")
end
end
End

Recipe:
chef_handler "Opscode::CookbookVersionsHandler" do
source "#{node["chef_handler"]["handler_path"]}/chf.rb"
supports :report => true
action :enable
End

At the end of the client run, the Handler will run, too. But I don’t get
some output:

Running handlers:

  • Opscode::CookbookVersionsHandler
    Running handlers complete

Chef Client finished, 4/117 resources updated in 20.13747256 seconds

How can I debug the missing Chef::Log message?

Thanks,
Christian

Am 16.04.14 20:25 schrieb "Daniel DeLeo" unter dan@kallistec.com:

On Wednesday, April 16, 2014 at 4:16 AM, Christian Fröstl wrote:

Hi there,

I have problems with understanding the logging procedure with chef.

I can log some information by using the following syntax:
log „foo" do
level :debug
end

Now I find in some cookbooks the following spelling:
Chef::Log.debug("Node has Chef Server Recipe?
#{node.recipe?("chef-server")}“)

This blog post is a pretty awesome and thorough description of how
chef-client has two stages: compile and converge:
http://erik.hollensbe.org/2013/03/16/the-chef-resource-run-queue/

Chef::Log.debug is a method call that writes a string to the logger,
which then writes it do some device (or not, depending on your log level,
etc.). The log resource puts an item in the resource_collection queue. In
the converge phase chef iterates over this queue, and will eventually run
this code
https://github.com/opscode/chef/blob/master/lib/chef/provider/log.rb
which you can see is more or less the same as Chef::Log.debug(). So the
primary difference is the timing.

What does Chef::Log.debug exactly do?
I do not get any output if i run the chef-client in normal or in debug
mode. What is the STDOUT from Chef::Log?

Did you configure chef to log to a file? Check your client.rb.

By the way, I am not really sure what Chef:: represents. Where can I
find the class or module Chef?
In some scripts I the other references like Chef::Client::SANE_PATHS.
Where can I find the content of such references?

Sorry if the questions are a litte bit stupid, but I am right new in
writing Code.
One easy way to spelunk the code is to clone the git repo from here:
GitHub - chef/chef: Chef Infra, a powerful automation platform that transforms infrastructure into code automating how infrastructure is configured, deployed and managed across any environment, at any scale and use git grep to search the
codebase.

Thank you very much,

Christian
HTH,

--
Daniel DeLeo

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: http://www.aquezada.com/staff/julian * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]