bref icon indicating copy to clipboard operation
bref copied to clipboard

Cannot create log directory, when not using file logs

Open atymic opened this issue 4 weeks ago • 3 comments

Description:

Error:

UnexpectedValueException: There is no existing directory at "/var/task/storage/logs" and it could not be created: Read-only file system
#0 /vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php(241): Monolog\Handler\StreamHandler::createDir
#1 /vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php(141): Monolog\Handler\StreamHandler::write
#2 /vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(44): Monolog\Handler\AbstractProcessingHandler::handle
#3 /vendor/monolog/monolog/src/Monolog/Logger.php(391): Monolog\Logger::addRecord
#4 /vendor/monolog/monolog/src/Monolog/Logger.php(685): Monolog\Logger::emergency
#5 /vendor/laravel/framework/src/Illuminate/Log/Logger.php(184): Illuminate\Log\Logger::writeLog
#6 /vendor/laravel/framework/src/Illuminate/Log/Logger.php(61): Illuminate\Log\Logger::emergency
#7 /vendor/laravel/framework/src/Illuminate/Log/LogManager.php(162): Illuminate\Log\LogManager::{closure:Illuminate\Log\LogManager::get():161}
#8 /vendor/laravel/framework/src/Illuminate/Support/helpers.php(399): tap
#9 /vendor/laravel/framework/src/Illuminate/Log/LogManager.php(161): Illuminate\Log\LogManager::get
#10 /vendor/laravel/framework/src/Illuminate/Log/LogManager.php(126): Illuminate\Log\LogManager::driver
#11 /vendor/laravel/framework/src/Illuminate/Log/LogManager.php(115): Illuminate\Log\LogManager::channel
#12 /vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(105): Illuminate\Foundation\Bootstrap\HandleExceptions::handleDeprecationError
#13 /vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(74): Illuminate\Foundation\Bootstrap\HandleExceptions::handleError
#14 /vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(258): Illuminate\Foundation\Bootstrap\HandleExceptions::{closure:Illuminate\Foundation\Bootstrap\HandleExceptions::forwardsTo():257}
#15 [internal](0): trigger_error
#16 /vendor/symfony/deprecation-contracts/function.php(25): trigger_deprecation
#17 /vendor/symfony/http-foundation/Request.php(742): Symfony\Component\HttpFoundation\Request::get
#18 /vendor/laravel/framework/src/Illuminate/Http/Request.php(408): Illuminate\Http\Request::get

The strange thing is this happens when all channels are set to stderr

LOG_CHANNEL=stderr
LOG_STACK=stderr
LOG_LEVEL=debug
LOG_DEPRECATIONS_CHANNEL=stderr

Will try to trace further, maybe due to bref service provider not hooking?

How to reproduce:

  • Bref Version: ^2.4
  • Additional Bref Packages:
    • bref/extra-php-extensions: ^1.7
    • bref/laravel-bridge: ^2.5
  • Layer: php-84

Runtime Details:

  • PHP Version: 8.4.8
  • Laravel Version: 11.x
  • Laravel Octane: v2.5 (FrankenPHP runtime)

atymic avatar Dec 02 '25 23:12 atymic

Thanks for the report, that's weird indeed, the Laravel Bridge was updated long ago to also re-configure the "emergency" log driver to stderr: https://github.com/brefphp/laravel-bridge/blob/c3e80249ab00d87f3587a681b8a113995a727909/src/BrefServiceProvider.php#L171-L173

I'm wondering about two possibilities:

  • either your error happens very very early, before the Laravel bridge is registered
  • or the if (Config::get('logging.channels.emergency.path') === storage_path('logs/laravel.log')) { doesn't match in your case, maybe logging.channels.emergency.path has changed in a new Laravel version, or you have changed it in your system?

mnapoli avatar Dec 03 '25 11:12 mnapoli

Seems like this was fixed on Laravel 11.46.2 with support for Symfony 7.4

https://github.com/laravel/framework/releases/tag/v11.46.2

deleugpn avatar Dec 04 '25 17:12 deleugpn

The deprecation was fixed, but I guess the issue is the first of the two you mentioned. I double checked and the Config::get('logging.channels.emergency.path') === storage_path('logs/laravel.log') eval'd to true, so it should have been overwritten. I manually did the same override in my config to set it to std err, which fixed the issue. Maybe worth adding to the docs to do it ahead of time?

atymic avatar Dec 06 '25 15:12 atymic

Do you have the Vapor dependency installed? We've had some reports of conflicts between Vapor and the Bref bridge.

mnapoli avatar Dec 15 '25 12:12 mnapoli

For me, it was just a matter of upgrading from a minor version below 11.46.2 to the latest Laravel 11 version and everything just started working again as it always has.

From my investigation, I noticed that the issue seems to be caused if you have your project pulling Symfony 7.4 components under the hood, but using a Laravel version that is not compatible yet. What happens is that extremely early in the execution flow (e.g. public/index.php, the code will end up triggering deprecated code from Symfony. Laravel hasn't even had a chance to fully bootstrap yet and the deprecation has already been triggered, which leads to the issue you've experienced.

deleugpn avatar Dec 15 '25 12:12 deleugpn

No vapor dependency. As @deleugpn mentioned, that was the cause, I guess the only thing I can suggest is the docs say to modify the config, instead of trying to do it pragmatically

atymic avatar Dec 15 '25 15:12 atymic