【问题标题】:How to write debug messages to Silverstripe log file如何将调试消息写入 Silverstripe 日志文件
【发布时间】:2023-11-28 14:37:01
【问题描述】:

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

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

Debug::show($variable);
Debug::message("Debug message goes here");

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

【问题讨论】:

    标签: php silverstripe


    【解决方案1】:

    您可以执行以下操作:

    在 mysite/_config.php 中

    SS_Log::add_writer(new SS_LogFileWriter('silverstripe.log'), SS_Log::WARN, '>');
    

    在您的代码中:

    SS_Log::log("Dammit, an issue with variable ".$var, SS_Log::WARN);
    

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

    此外,阅读 framework/dev/Log.php 中的代码将使您更深入地了解优先级的工作原理。

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

    【讨论】:

      【解决方案2】:

      最简单的解决方案实际上非常接近您最初的尝试。

      Debug::log("output");
      

      这将输出到站点根目录中的debug.log 文件。

      【讨论】: