Monolog Logger Compatibility Fix
February 11, 2025 Β· AI Conversations
Fatal error: Declaration of MonologLogger::emergency(Stringable|string $message, array $context = []): void must be compatible with PsrLogLoggerInterface::emergency($message, array $context = []) in /var/www/html/vendor/monolog/monolog/src/Monolog/Logger.php on line 682
Fatal error: Uncaught Error: Class "MonologLogger" not found in /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/AbstractHandler.php:60 Stack trace: #0 /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/AbstractHandler.php(38): MonologHandlerAbstractHandler->setLevel() #1 /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php(49): MonologHandlerAbstractHandler->__construct() #2 /var/www/html/vendor/illuminate/log/LogManager.php(187): MonologHandlerStreamHandler->__construct() #3 /var/www/html/vendor/illuminate/log/LogManager.php(141): IlluminateLogLogManager->createEmergencyLogger() #4 /var/www/html/vendor/illuminate/log/LogManager.php(124): IlluminateLogLogManager->get() #5 /var/www/html/vendor/illuminate/log/LogManager.php(681): IlluminateLogLogManager->driver() #6 /var/www/html/vendor/roots/acorn/src/Illuminate/Foundation/Exceptions/Handler.php(317): IlluminateLogLogManager->error() #7 /var/www/html/vendor/roots/acorn/src/Illuminate/Foundation/Exceptions/Handler.php(278): IlluminateFoundationExceptionsHandler->reportThrowable() #8 /var/www/html/vendor/roots/acorn/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(183): IlluminateFoundationExceptionsHandler->report() #9 [internal function]: IlluminateFoundationBootstrapHandleExceptions->handleException() #10 {main} thrown in /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/AbstractHandler.php on line 60
manually
### **1. Check Your Monolog Version**
Run the following command inside your project directory:
composer show monolog/monolog
If it shows an outdated version, you need to update it.
### **2. Update Monolog Manually**
Run the following command to update Monolog:
composer require monolog/monolog:^3.0 --with-dependencies
If your project requires Monolog 2.x for compatibility reasons, use:
composer require monolog/monolog:^2.9 --with-dependencies
### **3. Clear Composer Cache & Regenerate Autoload Files**
After updating, clear the Composer cache:
composer clear-cache
composer dump-autoload
### **4. Delete the `vendor` Folder and Reinstall Dependencies**
If the issue persists, delete the `vendor` folder and `composer.lock` file, then reinstall dependencies:
rm -rf vendor composer.lock
composer install
### **5. Verify Compatibility with Laravel**
Check your Laravel version:
php artisan --version
– **Laravel 9+** requires Monolog 3.x.
– **Laravel 8 and below** require Monolog 2.x.
Ensure your Laravel version supports the installed Monolog version.
### **6. Restart Your PHP Service**
If you are running Laravel with a local server or a Docker container, restart it:
php artisan serve
Or restart your Docker container:
docker-compose down && docker-compose up -d
After completing these steps, your Monolog issue should be resolved. Let me know if you encounter any further issues! π
descrip. : Sends your logs to files, sockets, inboxes, databases and various web services
keywords : log, logging, psr-3
versions : * 3.7.0
released : 2024-06-28, 7 months ago
type : library
license : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : https://github.com/Seldaek/monolog
source : [git] https://github.com/Seldaek/monolog.git f4393b648b78a5408747de94fca38beb5f7e9ef8
dist : [zip] https://api.github.com/repos/Seldaek/monolog/zipball/f4393b648b78a5408747de94fca38beb5f7e9ef8 f4393b648b78a5408747de94fca38beb5f7e9ef8
path : /var/www/html/vendor/monolog/monolog
names : monolog/monolog, psr/log-implementation
support
issues : https://github.com/Seldaek/monolog/issues
source : https://github.com/Seldaek/monolog/tree/3.7.0
autoload
psr-4
Monolog => src/Monolog
requires
php >=8.1
psr/log ^2.0 || ^3.0
requires (dev)
aws/aws-sdk-php ^3.0
doctrine/couchdb ~1.0@dev
elasticsearch/elasticsearch ^7 || ^8
ext-json *
graylog2/gelf-php ^1.4.2 || ^2.0
guzzlehttp/guzzle ^7.4.5
guzzlehttp/psr7 ^2.2
mongodb/mongodb ^1.8
php-amqplib/php-amqplib ~2.4 || ^3
phpstan/phpstan ^1.9
phpstan/phpstan-deprecation-rules ^1.0
phpstan/phpstan-strict-rules ^1.4
phpunit/phpunit ^10.5.17
predis/predis ^1.1 || ^2
ruflin/elastica ^7
symfony/mailer ^5.4 || ^6
symfony/mime ^5.4 || ^6
suggests
aws/aws-sdk-php Allow sending log messages to AWS services like DynamoDB
doctrine/couchdb Allow sending log messages to a CouchDB server
elasticsearch/elasticsearch Allow sending log messages to an Elasticsearch server via official client
ext-amqp Allow sending log messages to an AMQP server (1.0+ required)
ext-curl Required to send log messages using the IFTTTHandler, the LogglyHandler, the SendGridHandler, the SlackWebhookHandler or the TelegramBotHandler
ext-mbstring Allow to work properly with unicode symbols
ext-mongodb Allow sending log messages to a MongoDB server (via driver)
ext-openssl Required to send log messages using SSL
ext-sockets Allow sending log messages to a Syslog server (via UDP driver)
graylog2/gelf-php Allow sending log messages to a GrayLog2 server
mongodb/mongodb Allow sending log messages to a MongoDB server (via library)
php-amqplib/php-amqplib Allow sending log messages to an AMQP server using php-amqplib
rollbar/rollbar Allow sending log messages to Rollbar
ruflin/elastica Allow sending log messages to an Elastic Search server
provides
psr/log-implementation 3.0.0
—
### **1. Ensure the Correct PSR/Log Version**
Your Monolog requires **`psr/log` version `^2.0 || ^3.0`**. Check which version is installed:
composer show psr/log
If it's outdated, update it:
composer require psr/log:^3.0 --with-dependencies
—
### **2. Remove and Reinstall Dependencies**
Delete your `vendor` folder and `composer.lock` file:
rm -rf vendor composer.lock
Then reinstall everything:
composer install
—
### **3. Dump Autoload and Clear Cache**
Run the following commands:
composer dump-autoload
php artisan cache:clear
php artisan config:clear
php artisan config:cache
—
### **4. Restart PHP and Server**
Restart your services:
sudo systemctl restart php8.3-fpm
sudo systemctl restart apache2
Or restart your Laravel application if using Docker:
docker-compose down && docker-compose up -d
—
### **5. Check Your Laravel Dependencies**
If you are using **Laravel 8 or below**, downgrade Monolog:
composer require monolog/monolog:^2.9 --with-dependencies
If your Laravel version is **9+**, keep Monolog 3.
—
After these steps, your Monolog error should be fixed. Let me know if it persists! π
—
### **1. Edit `Logger.php` in Monolog**
Open the file:
π `/var/www/html/vendor/monolog/monolog/src/Monolog/Logger.php`
Find this method (around line `682`):
public function emergency(Stringable|string $message, array $context = []): void
Replace it with:
public function emergency($message, array $context = []): void
### **2. Verify the `LoggerInterface.php` File**
Check:
π `/var/www/html/vendor/psr/log/src/LoggerInterface.php`
Ensure the function is defined as:
public function emergency($message, array $context = []): void;
—
### **3. Clear Laravel Cache**
After modifying the files, clear the cache:
php artisan cache:clear
php artisan config:clear
php artisan config:cache
php artisan optimize:clear
—
### **4. Restart PHP and Web Server**
If using Apache:
sudo systemctl restart apache2
If using PHP-FPM:
sudo systemctl restart php8.3-fpm
Or if using Docker:
docker-compose down && docker-compose up -d
—
### **5. Test the Fix**
Try accessing your Laravel application again. If the error is gone, the issue is fixed. If it persists, you may need to manually adjust other Monolog methods with the same type hint issue.
Let me know if you need further assistance! π
IlluminateView
ViewException
Show exception properties
in /var/www/html/web/wp/wp-includes/media.php (line 1372)
*/ if ( is_ssl() && ! str_starts_with( $image_baseurl, 'https' ) ) { // Since the `Host:` header might contain a port we should // compare it against the image URL using the same port. $parsed = parse_url( $image_baseurl ); $domain = $parsed['host']; if ( isset( $parsed['port'] ) ) { $domain .= ':' . $parsed['port']; } if ( $_SERVER['HTTP_HOST'] === $domain ) { $image_baseurl = set_url_scheme( $image_baseurl, 'https' );
—
### **How to Manually Fix It**
#### **1. Debug `$image_baseurl` in `media.php`**
Open this file:
π `/var/www/html/web/wp/wp-includes/media.php`
Find this block (around line `1372`):
$parsed = parse_url($image_baseurl);
$domain = $parsed['host'];
Change it to:
$parsed = parse_url($image_baseurl);
if ($parsed === false || !isset($parsed['host'])) {
error_log("Invalid image URL: " . print_r($image_baseurl, true));
return $image_baseurl; // Return as is to avoid breaking the site
}
$domain = $parsed['host'];
This will log any invalid URLs and prevent the error.
—
#### **2. Check for Empty or Malformed URLs**
Since `$image_baseurl` comes from WordPress media handling, check:
– In **WordPress Admin β Settings β General**, ensure **WordPress Address (URL)** and **Site Address (URL)** are correctly set.
– Run this in the database to check for broken image URLs:
SELECT ID, post_title, guid FROM wp_posts WHERE post_type = 'attachment' AND guid NOT LIKE 'http%';
If any entries don't start with `http`, fix them manually.
—
#### **3. Disable Plugins and Theme Temporarily**
Some plugins or your theme (`all4cloud`) might be modifying image URLs incorrectly.
– Switch to a default theme (`Twenty Twenty-Four`) to see if the issue persists.
– Disable image-related plugins (e.g., caching, optimization, or CDN plugins).
—
#### **4. Verify Image URLs in Your Blade File**
Since the error appears in `content-page.blade.php`, find where you're handling images:
π `/var/www/html/web/app/themes/all4cloud/resources/views/partials/content-page.blade.php`
If you're using:
{{ get_the_post_thumbnail_url() }}
Modify it to:
@if(get_the_post_thumbnail_url())
<img src="{{ get_the_post_thumbnail_url() }}" alt="Image">
@else
<p>No Image Available</p>
@endif
—
### **Final Step: Clear Cache**
After making these changes, clear cache:
wp cache flush
php artisan cache:clear
php artisan config:clear
php artisan config:cache
Then restart your server:
sudo systemctl restart apache2
—
Now, reload your site. If the error is gone, it was due to a malformed image URL. Let me know if you need more help! π
1. **Bug Fixes & Security** β If this issue is caused by a WordPress bug, updating can resolve it.
2. **Core Function Updates** β The `parse_url()` function behavior might be affected by outdated WordPress or PHP versions.
3. **Better Media Handling** β New WordPress versions often improve media management and URL parsing.
—
### **What Should You Do?**
1. **Check Your WordPress Version**
Run this command inside your WordPress directory:
wp core version
If it's outdated, update it.
2. **Check Your PHP Version**
Run:
php -v
If it's below **PHP 8.1**, update to at least PHP **8.1 or 8.2**.
3. **Test Before Updating**
– Backup your site (`wp db export backup.sql`).
– Test the update on a staging environment before doing it on production.
4. **Update WordPress (If Needed)**
Run:
wp core update
wp plugin update --all
wp theme update --all
5. **Check If the Issue Persists**
After updating, clear the cache:
wp cache flush
php artisan cache:clear
—
### **Conclusion**
– If your WordPress is **already updated**, no need to update again.
– If it's outdated, updating **might** fix the issue automatically.
– Make sure PHP is **8.1+** for compatibility.
Let me know if you need guidance on updating safely! π