Logging to file in Prestashop

If you need to debug a variable or function in Prestashop (PHP, not Smarty) you can use this piece of code. Logging in Prestashop is not very well documented, so I had to dive into the code to figure out how to do it:

$logger = new FileLogger(0); //0 == debug level, logDebug() won’t work without this.
$logger->setFilename(_PS_ROOT_DIR_.”/log/debug.log”);
$logger->logDebug(“message 1″);
$logger->logDebug(“message 2″);

Debug messages will look like this (inside “/log/debug.log” at root dir in Prestashop):

*DEBUG* 2014/02/11 – 14:31:48: Hello world

I hope this helps somebody :-). Cheers.

12:06 PMPosted by in Uncategorized | 2 comments

Comments (2 Responses)

  1. Hey it is quite easy to debug multiple variables, than the ordinary Logger.Thanks for the code and you saved my time man

Add Your Comment

Your email address will not be published.