12

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

8
  • Is logging enabled in system configuration? Is var/log/ writable by your web user (apache, httpd, www-data, etc.)
    – laketuna
    May 22, 2015 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, 2015 at 13:42
  • Perhaps Mage core isn't loaded? Maybe try Mage::app() May 24, 2015 at 0:08
  • @TimHallman how would magento work without core? The site works just fine
    – Yorrd
    May 25, 2015 at 14:05
  • Because it's sitemap.php. Try logging in app/code/local/Mage/Sitemap/Model/Observer.php rather than Sitemap.php May 25, 2015 at 15:12

5 Answers 5

12

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

1
  • 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, 2015 at 8:53
32

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

3
  • Or for instance a sitemap.log in case you don't want your sitemap logs mixed with random stuff . May 29, 2015 at 8:24
  • @JulienLachal. True. The filename can be anything.
    – Marius
    May 29, 2015 at 8:32
  • please see my edit, this does not work either
    – Yorrd
    May 29, 2015 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.

1
  • 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, 2015 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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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