Domanda

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

È stato utile?

Soluzione

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

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top