Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write debug messages to Silverstripe log file

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

like image 970
BaronGrivet Avatar asked Jan 27 '26 17:01

BaronGrivet


1 Answers

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

like image 156
jfbarrois Avatar answered Jan 29 '26 09:01

jfbarrois



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!