문제

I've got a Silverstripe 3.1 site in development and want to write messages to the default log file - silverstripe.log

This is what we use to output variables or messages to the screen:

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

What is the simplest way to output these to the silverstripe.log file? I've been looking through the documentation and can't find the correct approach: http://doc.silverstripe.com/framework/en/topics/debugging

도움이 되었습니까?

해결책

You could do the following:

in mysite/_config.php

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

in your code:

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

More at http://doc.silverstripe.com/framework/en/topics/error-handling

Also reading the code in framework/dev/Log.php will give you more insight on how priorities work.

PS: ensure to define 'silverstripe.log' in a folder writable by the apache user

다른 팁

The simplest solution is actually pretty close to your original attempt.

Debug::log("output");

This will output to a debug.log file in the site root.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top