Silverstripe 4 error log

巧了我就是萌 提交于 2021-01-27 20:33:29

问题


How can I log errors to file log in SilverStripe 4? I mean all errors causing 'Internal server error' info from SS

In SilverStripe it was :

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

Documentation says that I need to do something like:

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

I try this but cannot get this to work :(


回答1:


Try to add to your .env file (https://docs.silverstripe.org/en/4/getting_started/environment_management/) such string:

SS_ERROR_LOG = "silverstripe.log"



回答2:


To create a custom log try: use Monolog\Handler\StreamHandler; use Monolog\Logger; Then later: $logger = new Logger("my_name"); $logger->pushHandler(new StreamHandler('./silverstripe-custom.log', Logger::INFO)); $logger->info('hi there'); You should find silverstripe-custom.log in the project root.



来源:https://stackoverflow.com/questions/50430231/silverstripe-4-error-log

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