Use logging and error handling with Sitemagic CMS

Logging and error handling is an important aspect of designing reliable and robust web applications. It also greately simplifies the process of debugging - finding and correcting bugs.
Sitemagic CMS implements error handling that logs PHP related errors that occure. Warning and error messages are stored in the SMLog data source (see the data/SMLog.xml.php file for a standard Sitemagic CMS installation, or the SMLog database table if MySQL has been enabled).
Unhandled exceptions may also occure - these are displayed to the user with a more user friendly error message along with a full stack trace, allowing a developer to immediately identify the problem.

Implementing logging
Implementing logging in a custom extension is rather simple. Sitemagic CMS features a simple logging mechanism that allows the developer to write debug information to the SMLog data source, using the SMLog class.
if (checkUsername($username) === false)
    SMLog::Log(__FILE__, __LINE__, "WARNING: Login attempt failed!");
Notice how __FILE__ and __LINE__ is used to grap the filename and line currently being intepreted by PHP, and passed to the Log function. The SMLog data source now contains an accurate reference to the file and line logging the error.