问题
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