Centralizing debug output

23 views
Skip to first unread message

Jakob Kristoferitsch

unread,
Aug 20, 2012, 10:42:55 AM8/20/12
to SilverStripe Core Development
Hi,
as part of my GSoC project (developer dashboard), I thought about how
the way logging/debugging is done in SilverStripe could be changed. Ingo
summarized the current state of the framework code at
<http://open.silverstripe.org/ticket/5768>

I think that direct output should be avoided, even for debug purposes.
All debug output should be passed through a central logging class instead.

A demonstration of that approach is my debug_rewrite branch (see
<https://github.com/jakr/sapphire/tree/debug_rewrite>).
Instead of direct echos, all output in the Debug class is passed to a
SS_ZendLog instance. By default, this is logger has a DebugEchoWriter
attached, a Zend_Log_Writer_Abstract that then echos the information
directly onto the page. By calling Debug::replaceDefaultOutputWriter it
is possible to replace that output writer with any other
Zend_Log_Writer_Abstract instance.

The rewritten code is designed to be used in combination with the
developer dashboard (<https://github.com/jakr/developer_dashboard/>). If
that module is installed, all error output can be redirected to the
dashboard by adding two lines to _config.php:
$writers = DashboardLog::get_log_wrapper('DEBUG',
true)->logger->getWriters();
Debug::replaceDefaultOutputWriter($writers[0]);

Of course, it is also possible to replace the writer with one of the
default Zend_Log writers (File, Mail, DB) or with a custom one.

Has anyone else thought about this? Are there better approaches?

Yours
Jakob

P.S.: I'll only have limited access to the internet for the next month,
so my responses will be sporadic.
Reply all
Reply to author
Forward
0 new messages