How can the error "Class 'Monolog\Logger' not found" be resolved in PHP when working with Monolog?
The error "Class 'Monolog\Logger' not found" occurs when the Monolog library is not properly included or autoloaded in the PHP script. To resolve this issue, you need to include the Monolog library using Composer or manually require the necessary files before using the Monolog classes in your code.
// Include the Composer autoload file
require 'vendor/autoload.php';
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
// Create a logger
$log = new Logger('name');
$log->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));
// Log a message
$log->warning('This is a warning message');
Keywords
Related Questions
- What are some common pitfalls to avoid when using PHP for user input and display?
- What are the limitations of using PHP to retrieve a user's location information, such as city or region?
- What improvements can be made to the code to ensure that all records in the database are displayed in separate table cells?