如何将调试消息写入Silverstripe日志文件

Bar*_*vet 3 php silverstripe

我有一个正在开发的Silverstripe 3.1站点,并希望将消息写入默认日志文件 - silverstripe.log

这是我们用来向屏幕输出变量或消息的方法:

Debug::show($variable);
Debug::message("Debug message goes here");
Run Code Online (Sandbox Code Playgroud)

将这些输出到silverstripe.log文件的最简单方法是什么?我一直在查看文档,找不到正确的方法:http://doc.silverstripe.com/framework/en/topics/debugging

小智 11

您可以执行以下操作:

在mysite/_config.php中

SS_Log::add_writer(new SS_LogFileWriter('silverstripe.log'), SS_Log::WARN, '>');
Run Code Online (Sandbox Code Playgroud)

在你的代码中:

SS_Log::log("Dammit, an issue with variable ".$var, SS_Log::WARN);
Run Code Online (Sandbox Code Playgroud)

更多信息,请访问http://doc.silverstripe.com/framework/en/topics/error-handling

另外,阅读框架/ dev/Log.php中的代码可以让您更深入地了解优先级的工作方式.

PS:确保在apache用户可写的文件夹中定义'silverstripe.log'