{"id":367,"date":"2021-03-23T16:32:39","date_gmt":"2021-03-24T00:32:39","guid":{"rendered":"http:\/\/www.antunkarlovac.com\/blog\/?p=367"},"modified":"2021-03-23T16:32:39","modified_gmt":"2021-03-24T00:32:39","slug":"logging-in-salesforce-commerce-cloud","status":"publish","type":"post","link":"https:\/\/www.antunkarlovac.com\/blog\/2021\/03\/23\/logging-in-salesforce-commerce-cloud\/","title":{"rendered":"Logging in Salesforce Commerce Cloud"},"content":{"rendered":"<p>I&#8217;ve been learning SFCC recently, and found that I was missing a simple guide for server logging, so I decided to write one.<\/p>\n<p><strong>Basic Usage<\/strong><br \/>\nFirst you need to get a reference to a Log object, and then you issue log statements that are the level you want (debug, info, warn, error, fatal):<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar Logger = require('dw\/system\/Logger');\r\nvar log = Logger.getLogger('my_category');\r\nlog.warn('createRequest call took {0}ms, which is more than the threshold of {1}ms', 999, 500);\r\n<\/pre>\n<p>By passing just one argument to <code>getLogger()<\/code>, you will be putting your log statements in the default location &#8211; more on that below.<\/p>\n<p><strong>Finding Log Entries<\/strong><br \/>\nThere are two ways to access logs, through Business Manager (BM), neither of which are immediately obvious:<\/p>\n<ol>\n<li>The log center<\/li>\n<li>The actual log files<\/li>\n<\/ol>\n<p>The <strong>log center<\/strong> is accessed in Administration \/ Site Development \/ Development Setup, although it requires specific permissions:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2021\/03\/logcenter.jpg\" alt=\"logcenter\" width=\"308\" height=\"99\" class=\"aligncenter size-full wp-image-369\" srcset=\"https:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2021\/03\/logcenter.jpg 308w, https:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2021\/03\/logcenter-300x96.jpg 300w\" sizes=\"(max-width: 308px) 100vw, 308px\" \/><\/p>\n<p>The other way is to access the log files directly &#8211; also via BM &#8211; in <strong>Administration \/ Site Development \/ Development Setup<\/strong>, then click on <strong>Folder Browser<\/strong>, and navigate to the <strong>Logs<\/strong> directory:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2021\/03\/folder_browser.jpg\" alt=\"folder_browser\" width=\"386\" height=\"165\" class=\"aligncenter size-full wp-image-371\" srcset=\"https:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2021\/03\/folder_browser.jpg 386w, https:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2021\/03\/folder_browser-300x128.jpg 300w\" sizes=\"(max-width: 386px) 100vw, 386px\" \/><\/p>\n<p><strong>Log Files<\/strong><br \/>\nIf you initialize the log object with one argument (e.g. <code>getLogger('my_category')<\/code>), then you are specifying the category only, and the log entries will appear in a generic file. The file will be named something like customwarn-ecom-sandbox-SANDBOX-appserver-DATE.log where &#8220;warn&#8221; is the log level.<\/p>\n<p>The category will appear in the log entry:<\/p>\n<p><code>[2021-03-23 23:46:32.086 GMT] WARN PipelineCallServlet|212645572|SITE_NAME|CONTROLLER_NAME|PipelineCall|iEHTL3fGnn custom.my_category []  createRequest call took 999ms, which is more than the threshold of 500ms<br \/>\n<\/code><\/p>\n<p>You can add a second parameter when getting the log object, which will create a new log file. This may be useful if you are developing a cartridge and want all of that cartridge&#8217;s logging information stored in one place:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar log = Logger.getLogger('my_cartridge', 'my_category');\r\n<\/pre>\n<p>That will create a dedicated log file like so, in the same location as the other log files:<\/p>\n<p><code>custom-my_cartridge-ecom-SANDBOX-ITENTIFIERS-DATE.log<\/code><\/p>\n<p><strong>Enabling Log Levels<\/strong><br \/>\nThe log level you want to use must be enabled in BM under <strong>Administration \/ Operations \/ Custom Log Settings<\/strong>, in the <strong>Custom Log Targets<\/strong> section:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2021\/03\/enabled.jpg\" alt=\"enabled\" width=\"541\" height=\"281\" class=\"aligncenter size-full wp-image-375\" srcset=\"https:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2021\/03\/enabled.jpg 541w, https:\/\/www.antunkarlovac.com\/blog\/wp-content\/uploads\/2021\/03\/enabled-300x156.jpg 300w\" sizes=\"(max-width: 541px) 100vw, 541px\" \/><\/p>\n<p>If it&#8217;s not, then the log entries won&#8217;t appear.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been learning SFCC recently, and found that I was missing a simple guide for server logging, so I decided to write one. Basic Usage First you need to get a reference to a Log object, and then you issue log statements that are the level you want (debug, info, warn, error, fatal): By passing &hellip; <a href=\"https:\/\/www.antunkarlovac.com\/blog\/2021\/03\/23\/logging-in-salesforce-commerce-cloud\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Logging in Salesforce Commerce Cloud<\/span><\/a><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts\/367"}],"collection":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/comments?post=367"}],"version-history":[{"count":7,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts\/367\/revisions"}],"predecessor-version":[{"id":377,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts\/367\/revisions\/377"}],"wp:attachment":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/media?parent=367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/categories?post=367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/tags?post=367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}