11

I have overwritten Sitemap.php in app/code/local/Mage/Sitemap/Model/Sitemap.php. The file seems to be used, if I remove all contents, there's an error as expected.

I copied the complete content of the standard Sitemap.php, with one single change. I added

public function generateXml() {
    Mage::log('test');
    ...
}

When I do this anywhere else, it prints test in var/log/system.log as expected, only in this file, it does not log the message.

Any help is greatly appreciated


EDIT

using

Mage::log('text', null, <file>, true);

does not work either

  • Is logging enabled in system configuration? Is var/log/ writable by your web user (apache, httpd, www-data, etc.) – musicliftsme May 22 '15 at 13:39
  • logging works in SitemapController.php, so yes, it is. and yes var/log is writable. Thanks for your ideas – Yorrd May 22 '15 at 13:42
  • Perhaps Mage core isn't loaded? Maybe try Mage::app() – Tim Hallman May 24 '15 at 0:08
  • @TimHallman how would magento work without core? The site works just fine – Yorrd May 25 '15 at 14:05
  • Because it's sitemap.php. Try logging in app/code/local/Mage/Sitemap/Model/Observer.php rather than Sitemap.php – Tim Hallman May 25 '15 at 15:12
10

I would assume, the file is loaded but the method is not called. So just set a breakpoint (or bad way a die()) into your method and make sure it is called.

After magento is initialized Mage::log at least with the $force parameter writes its log

  • Yes. Thanks. I guess I'll open another question why my generateXml is not loaded. Because no, it does not reach the breakpoint. – Yorrd May 29 '15 at 8:53
23

Use Mage::log('text here', null, 'system.log', true).
That should work all the time.

  • Or for instance a sitemap.log in case you don't want your sitemap logs mixed with random stuff . – Julien Lachal May 29 '15 at 8:24
  • @JulienLachal. True. The filename can be anything. – Marius May 29 '15 at 8:32
  • please see my edit, this does not work either – Yorrd May 29 '15 at 8:36
2

Another guess here - the sitemap generation is generally triggered by a cronjob. If your cronjob runs under a different user than your webuser and doesn't have the permissions to write to your existing system.log file you wouldn't get any entries.

  • True, but I'm testing it by just clicking "generate" on the sitemap admin page. So I'd assume he should have permission. EDIT: it does not work either if the permission is set to 777 – Yorrd May 29 '15 at 8:38
0

Give the right permit to your var/ folder:

chmod -Rv 777 var/

So use like this code below:

Mage::log(print_r($yourTest), null, 'customLogFile.log', true);

The print_r will prevent some errors related to the type of your variable.

0

Put this line in any function or file

Mage::log( "Your message - ", null, 'your-log-filename.log');

this file will be created at your inside your root folder path like

/var/log/your-log-filename.log

hope it will work for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.