Prestashop - how do I write to a log file?

依然范特西╮ 提交于 2019-12-31 03:02:13

问题


What php code should I use in a Prestashop module to write to a log file? I have used

Logger::addLog("something",1);

but it does not work.


回答1:


You can also store the log in file using below code.

$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″);

It will work!.

Thanks




回答2:


The log is saved in database in 'log' table (with your current prefix);




回答3:


Another alternative is to use PHP's

file_put_contents(_PS_ROOT_DIR_ . '/path/to/logfile',
                  $data . "\n",
                  FILE_APPEND);


来源:https://stackoverflow.com/questions/16132637/prestashop-how-do-i-write-to-a-log-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!