# 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`

```php
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

```php
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'
```

{% hint style="success" %}
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.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cmsfullform.com/documents/libraries/logger-and-monitor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
