Logging and error handling
Logging is an important step in qualified debugging (search for errors). Sitemagic CMS comes with the SMLog class, which enables easy logging anywhere in the code.
SMLog::Log(__FILE__, __LINE__, "Loading data");
if (data successfully loaded) SMLog::Log(__FILE__, __LINE__, "Successfully loaded data"); else SMLog::Log(__FILE__, __LINE__, "An error occured while loading data"); |
PHP errors and uncatched exceptions are automatically catched by error handlers. Ordinary errors are written to the SMLog data source, while exceptions are being displayed to the user with a user friendly error message and a complete stack trace, which makes it easy to find the given error.
SMLog class
| Function |
Return type |
Description |
| ::Log($errFile:string, $errLine:integer, $errMsg:string) |
|
Log error or message. The file in which the error occures is stored in __FILE__. A reference to the current line is available using __LINE__. Messages are written to the SMLog data source. |
| LogDeprecation($depClass:string, $depFunc:string) |
|
Log call to deprecated function (used when no alternative function is available). Example: SMLog::LogDeprecation(__CLASS__, __FUNCTION__); |
| LogDeprecation($depClass:string, $depFunc:string, $newClass:string, $newFunc:string) |
|
Log call to deprecated function (used when alternative function is available). Example: SMLog::LogDeprecation(__CLASS__, __FUNCTION__, __CLASS__, "NewFunction"); |