{"id":675,"date":"2017-07-26T12:22:56","date_gmt":"2017-07-26T12:22:56","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2017\/07\/26\/logging-in-chef-explained\/"},"modified":"2022-11-27T20:26:59","modified_gmt":"2022-11-27T20:26:59","slug":"logging-in-chef-explained","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/logging-in-chef-explained\/","title":{"rendered":"Chef Tutorials: Logging in Chef Explained"},"content":{"rendered":"<p><strong>Chef Server<\/strong><br>\nAll logs generated by the Chef server can be found in \/var\/log\/opscode. Each service enabled on the system also has a sub-directory in which service-specific logs are located, typically found in \/var\/log\/opscode\/service_name.<\/p>\n<p>The Chef server has built-in support for easily tailing the logs that are generated. To view all the logs being generated on the Chef server, enter the following command:<br>\n&gt; chef-server-ctl tail<\/p>\n<p><strong>To view logs for a specific service:<\/strong><br>\n&gt; chef-server-ctl tail SERVICENAME<br>\nwhere SERVICENAME should be replaced with name of the service for which log files will be viewed. SERVICENAME represents the name of any service that is listed after running the &#8220;&gt; chef-server-ctl service-list&#8221; subcommand.<\/p>\n<p><strong>Another way to view log files is to use the system utility tail:<\/strong><br>\n&gt; tail -50f \/var\/log\/chef-server\/opscode-chef\/current<br>\n&gt; tail -50f \/var\/log\/opscode\/opscode-chef\/current<\/p>\n<p><strong>Supervisor Logs<\/strong><br>\nSupervisor logs are created and managed directly by the service supervisor, and are automatically rotated when a the current log file reaches 1,000,000 bytes. 10 log files are kept. The latest supervisor log is always located in \/var\/log\/chef-server\/service_name\/current and rotated logs have a filename starting with @ followed by a precise tai64n timestamp based on when the file was rotated.<\/p>\n<p>Supervisor logs are available for the following services:<\/p>\n<ol>\n<li>bifrost<\/li>\n<li>bookshelf<\/li>\n<li>nginx<\/li>\n<li>opscode-erchef<\/li>\n<li>opscode-expander<\/li>\n<li>opscode-expander-reindexer<\/li>\n<li>opscode-solr4<\/li>\n<li>postgresql<\/li>\n<li>rabbitmq<\/li>\n<li>redis<\/li>\n<\/ol>\n<h3>nginx<\/h3>\n<p>The&nbsp;nginx&nbsp;service creates both supervisor and administrator logs. The administrator logs contain both access and error logs for each virtual host utilized by the Chef server. Each of the following logs require external log rotation.<\/p>\n<table border=\"1\">\n<colgroup>\n<col width=\"13%\">\n<col width=\"88%\"> <\/colgroup>\n<thead valign=\"bottom\">\n<tr>\n<th>Logs<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody valign=\"top\">\n<tr>\n<td>\/var\/log\/opscode\/nginx\/access.log<\/td>\n<td>The Web UI and API HTTP access logs.<\/td>\n<\/tr>\n<tr>\n<td>\/var\/log\/opscode\/nginx\/error.log<\/td>\n<td>The Web UI and API HTTP error logs.<\/td>\n<\/tr>\n<tr>\n<td>\/var\/log\/opscode\/nginx\/internal-account.access.log<\/td>\n<td>The&nbsp;opscode-account&nbsp;internal load-balancer access logs.<\/td>\n<\/tr>\n<tr>\n<td>\/var\/log\/opscode\/nginx\/internal-account.error.log<\/td>\n<td>The&nbsp;opscode-account&nbsp;internal load-balancer error logs.<\/td>\n<\/tr>\n<tr>\n<td>\/var\/log\/opscode\/nginx\/internal-authz.access.log<\/td>\n<td>The&nbsp;opscode-authz&nbsp;internal load-balancer access logs.<\/td>\n<\/tr>\n<tr>\n<td>\/var\/log\/opscode\/nginx\/internal-authz.error.log<\/td>\n<td>The&nbsp;opscode-authz&nbsp;internal load-balancer error logs.<\/td>\n<\/tr>\n<tr>\n<td>\/var\/log\/opscode\/nginx\/internal-chef.access.log<\/td>\n<td>The&nbsp;opscode-chef&nbsp;and&nbsp;opscode-erchef&nbsp;internal load-balancer access logs.<\/td>\n<\/tr>\n<tr>\n<td>\/var\/log\/opscode\/nginx\/internal-chef.error.log<\/td>\n<td>The&nbsp;opscode-chef&nbsp;and&nbsp;opscode-erchef&nbsp;internal load-balancer error logs.<\/td>\n<\/tr>\n<tr>\n<td>\/var\/log\/opscode\/nginx\/nagios.access.log<\/td>\n<td>The&nbsp;nagios&nbsp;access logs.<\/td>\n<\/tr>\n<tr>\n<td>\/var\/log\/opscode\/nginx\/nagios.error.log<\/td>\n<td>The&nbsp;nagios&nbsp;error logs.<\/td>\n<\/tr>\n<tr>\n<td>\/var\/log\/opscode\/nginx\/rewrite-port-80.log<\/td>\n<td>The rewrite logs for traffic that uses HTTP instead of HTTPS.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>To follow the logs for the service:<\/p>\n<div>\n<div>\n<pre> $ chef-server-ctl tail nginx<\/pre>\n<\/div>\n<\/div>\n<p><strong>Chef Client<\/strong><\/p>\n<p>Client.rb3 file might help you. Default value of log_location is STDOUT. You can give \/path\/to\/log_location in place of this. You can locate this client.rb file in C:\\chef\\client.rb or \/etc\/chef\/client.rb directories.<\/p>\n<p>Use the verbose logging that is built into the chef-client:<br>\n-l LEVEL, &#8211;log_level LEVEL<br>\nThe level of logging to be stored in a log file.<br>\n-L LOGLOCATION, &#8211;logfile c<br>\nThe location of the log file. This is recommended when starting any executable as a daemon. Default value: STDOUT.<\/p>\n<p><strong>Knife<\/strong><br>\nUse the verbose logging that is built into knife:<br>\n-V, &#8211;verbose<br>\nSet for more verbose outputs. Use -VV for maximum verbosity.<\/p>\n<p><strong>chef-solo<\/strong><br>\n-l LEVEL, &#8211;log_level LEVEL<br>\nThe level of logging to be stored in a log file.<\/p>\n<p>The Chef file and folder locations are different on Linux and Windows machines. This article explains the purpose of each&nbsp;file and the location.<\/p>\n<h4>Summary<\/h4>\n<table border=\"1\" width=\"100%\">\n<tbody>\n<tr>\n<th><\/th>\n<th>Linux<\/th>\n<th>Windows<\/th>\n<\/tr>\n<tr>\n<td>Cookbook location<\/td>\n<td>\/var\/chef\/cache\/cookbooks<\/td>\n<td>&nbsp;C:\\chef\\cache\\cookbooks<\/td>\n<\/tr>\n<tr>\n<td>Chef Client run log<\/td>\n<td>\/var\/log\/chef.log<\/td>\n<td>First run only<br>\nC:\\chef\\chef-client.log<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td>Subsequent Chef client runs<br>\nC:\\chef\\log\\client.log<\/td>\n<\/tr>\n<tr>\n<td>Error log<\/td>\n<td>\/var\/chef\/cache\/chef-stacktrace.out<\/td>\n<td>C:\\chef\\cache\\chef-stacktrace.out<\/td>\n<\/tr>\n<tr>\n<td>Ohai output<\/td>\n<td>\/var\/chef\/cache\/failed-run-data.json<\/td>\n<td>C:\\chef\\cache\\failed-run-data.json<\/td>\n<\/tr>\n<tr>\n<td>Recommended location for custom log files<\/td>\n<td>\/tmp\/cheflog.log<\/td>\n<td>C:\\Logs\\Chef\\cheflog.log<\/td>\n<\/tr>\n<tr>\n<td height=\"43\">Chef Client configuration<\/td>\n<td>\/etc\/chef\/client.rb<\/td>\n<td>C:\\chef\\client.rb<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>When you test your cookbook in Test Kitchen<\/h4>\n<p>The .kitchen.yml file contains the username to execute the Chef cookbook. It is specified under&nbsp;<strong>platforms<\/strong>:,&nbsp;<strong>transport<\/strong>:,&nbsp;<strong>username<\/strong>:<\/p>\n<p>Use that value in place of&nbsp;<strong>USER-NAME-FROM-KITCHEN-YML<\/strong>&nbsp;below.<\/p>\n<table border=\"1\" width=\"100%\">\n<tbody>\n<tr>\n<th><\/th>\n<th>Linux<\/th>\n<th>Windows<\/th>\n<\/tr>\n<tr>\n<td>Cookbook location<\/td>\n<td>\/tmp\/kitchen\/cookbooks<br>\n\/tmp\/kitchen\/cache\/cookbooks<\/td>\n<td>&nbsp;C:\\Users\\USER-NAME-FROM-KITCHEN-YML\\AppData\\Local\\Temp\\kitchen\\cookbooks<\/td>\n<\/tr>\n<tr>\n<td>Error log<\/td>\n<td>\/tmp\/kitchen\/cache\/chef-stacktrace.out<\/td>\n<td>C:\\Users\\USER-NAME-FROM-KITCHEN-YML\\AppData\\Local\\Temp\\kitchen\\cache\\chef-stacktrace.out<\/td>\n<\/tr>\n<tr>\n<td>Ohai output<\/td>\n<td>\/tmp\/kitchen\/cache\/failed-run-data.json<\/td>\n<td>C:\\Users\\USER-NAME-FROM-KITCHEN-YML\\AppData\\Local\\Temp\\kitchen\\cache\\failed-run-data.json<\/td>\n<\/tr>\n<tr>\n<td>Data bags<\/td>\n<td>\/tmp\/kitchen\/data_bags<\/td>\n<td>C:\\Users\\USER-NAME-FROM-KITCHEN-YML\\AppData\\Local\\Temp\\kitchen\\data_bags<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Cookbook location <\/strong><\/p>\n<p>When the Chef recipes are executed, all cookbooks are stored on the node. You can examine the code to make sure your latest changes are reflected on the machine.<\/p>\n<p><strong>The log of the Chef client run<\/strong><\/p>\n<p>The output of the Chef cookbook execution is in the chef.log or chef-client.log file<\/p>\n<p><strong>On Windows<\/strong><\/p>\n<p><strong>The log of the first Chef Client run and subsequent runs are stored in different log files.<\/strong>&nbsp;After the initial Chef Client run, the rest of the log entries are collected in the second file.<\/p>\n<p><strong>Stacktrace<\/strong><\/p>\n<p>Chef saves information on the hard drive when scripts are executed. If there is a failure,&nbsp;the stack trace of the last error is saved in the&nbsp;<strong>chef-stacktrace.out<\/strong>&nbsp;file.<\/p>\n<p><strong>Ohai output<\/strong><\/p>\n<p>All the information that Ohai collects on the instance, is saved in the&nbsp;<strong>failed-run-data.json<\/strong>file, even if there is no error. It is a great resource to get the server specific values.<\/p>\n<p><strong>Reference<\/strong><\/p>\n<p><a href=\"https:\/\/docs.chef.io\/server_logs.html\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/docs.chef.io\/server_logs.html<\/a><br>\n<a href=\"https:\/\/docs.chef.io\/debug.html\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/docs.chef.io\/debug.html<\/a><\/p>\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_98088\"><figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_42081\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_98088\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Chef Server All logs generated by the Chef server can be found in \/var\/log\/opscode. Each service enabled on the system also has a sub-directory in which service-specific logs are located, typically found in \/var\/log\/opscode\/service_name. The Chef server has built-in support for easily tailing the logs that are generated. To view all the logs being generated&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2845,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[88],"tags":[407,604,605,602,601,603],"class_list":["post-675","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chef","tag-chef","tag-chef-guide","tag-chef-recipe","tag-chef-tutorials","tag-logging-in-chef","tag-logs"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/675","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=675"}],"version-history":[{"count":6,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/675\/revisions"}],"predecessor-version":[{"id":31950,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/675\/revisions\/31950"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/2845"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}