Silverstripe 4错误日志

时间:2018-05-19 23:02:06

标签: silverstripe-4

如何在SilverStripe 4中将错误记录到文件日志? 我的意思是所有错误导致内部服务器错误'来自SS的信息

在SilverStripe中它是:

SS_Log::add_writer(new SS_LogFileWriter('/var/log/silverstripe/errors.log'), SS_Log::ERR);

文档说我需要做类似的事情:

SilverStripe\Core\Injector\Injector:
  Psr\Log\LoggerInterface: 
    calls:
      LogFileHandler: [ pushHandler, [ %$LogFileHandler ] ]
  LogFileHandler:
    class: Monolog\Handler\StreamHandler
    constructor:
      - "../silverstripe.log"
      - "info"

我试试这个,但无法让它发挥作用:(

2 个答案:

答案 0 :(得分:5)

尝试将这样的字符串添加到您的.env文件(https://docs.silverstripe.org/en/4/getting_started/environment_management/)中:

SS_ERROR_LOG = "silverstripe.log"

答案 1 :(得分:0)

要创建自定义日志,请尝试: use Monolog\Handler\StreamHandler; use Monolog\Logger; 然后再: $logger = new Logger("my_name"); $logger->pushHandler(new StreamHandler('./silverstripe-custom.log', Logger::INFO)); $logger->info('hi there'); 您应该在项目根目录中找到silverstripe-custom.log