Contents |
Hotaru will log PHP errors and warnings to the error_log.php file in your cache folder. You can view that log in your browser from Admin -> Maintenance -> Debug. You'll notice you can also delete debug files from that same page. It's a good idea to clear the logs every now and again, especially if they grow large.
Hotaru CMS has a few debugging functions that can help you with testing. This tutorial details how to log results from your plugin to a file in the /cache/debug_logs/ directory.
Note: To use this feature, enable Debug mode in Admin -> Settings
$h->openLog('log_test', 'a+');
The openLog function takes two parameters: a filename without an extension, and an access mode (list of modes here). Using the 'a+' mode as in this example will create the file if it doesn't exist, open it, and append new data to the end.
$h->writeLog('log_test', 'This message will be written to the log file');
Again, include the filename, and put your message in the second parameter. You can repeat this step for as many messages as you like.
$h->closeLog('log_test');
Example 1
This example creates a log file to track admin users:
if ($h->currentUser->role == 'admin') { $h->openLog('admin_visits', 'a+'); $h->writeLog('admin_visits', 'Admin ' . $h->currentUser->name . ' visited ' . $h->pageName); $h->closeLog('admin_visits'); }
Output:
18 Jan 2010 14:38:43: Moderator Nick visited index
Example 2
This example logs the execution time of a function. Note that the 'w' mode in openLog rewrites the file every time instead of appending the result to the end of the previous results:
$h->openLog('speed_test', 'w'); $start = microtime(true); // insert big function here $end = microtime(true); $time = $end - $start; $h->writeLog('speed_test', 'This function took ' . round($time, 2) . ' seconds to complete.'); $h->closeLog('speed_test');
Output:
18 Jan 2010 15:03:21: This function took 1.03 seconds to complete.