Logger & Monitor
Overview
Effective logging and performance monitoring are crucial aspects of any web application. PHP-Fast provides a built-in Logger
class for capturing important log messages such as errors, warnings, and informational messages and a Monitor
class for measuring execution time, memory usage, and CPU load to help optimize performance.
Logger
The Logger library allows you to record messages in different log levels. All logs are saved in:
writeable/logs/logger.log
Logger::info('This is an informational message.'); // Log informational message
Logger::warning('This is a warning message.'); // Log warning message
Logger::error('This is an error message.'); // Log error message
The Logger
class supports optional parameters for file name and line number, making it easier to pinpoint issues.
Monitor
use System\Libraries\Monitor;
// Call Monitor class
$performance = Monitor::endFramework();
// Format memory usage
$formattedMemory = Monitor::formatMemorySize($performance['memory_used']);
// Print results
echo "Execution Time: " . round($performance['execution_time'], 5) . " seconds <br>";
echo "Memory Used: " . $formattedMemory . "<br>";
echo "CPU Load: " . $performance['cpu_usage'] . "<br>";
// Output:
Execution Time: 0.01095 seconds
Memory Used: 512 KB
CPU Load: 0.32
// Note: Check your constant DEBUG_TIME is 'true'
Conclusion
The Logger and Monitor libraries in PHPFast make it easy to track your application's activity, detect issues, and improve performance. Logger helps record errors, warnings, and important messages, while Monitor measures execution time, memory usage, and CPU load, allowing developers to identify and fix problems efficiently.
Last updated
Was this helpful?