Asked 1 month ago by MercurialMariner601
Why Aren't My Laravel Job Logs Appearing When Using queue:work / queue:listen?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 1 month ago by MercurialMariner601
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
I have a Laravel job that logs certain actions when dispatched, but I'm not seeing any log entries when I run either queue:listen or queue:work. I created a job to log information, but nothing appears in my logs. I’m using the database queue connection (QUEUE_CONNECTION=database).
Here is the job's handle method:
PHPpublic function handle(): void { Log::info('HandleBattleProgress job started for houseId: ' . $this->houseId); try{ $battleMode = BattleMode::where('house_id', $this->houseId)->first(); Log::info('Getting the BattleMode', ['BattleMode' => $battleMode]); if (!$battleMode) { BattleMode::create([ 'house_id' => $this->houseId, 'start_xp' => 0, 'target_xp' => 1000, 'phase' => 'phase_1', 'battle_xp' => 0, 'is_in_battle' => false, ]); Log::info('Creating BattleMode'); } $house = House::find($this->houseId); Log::info('Getting The House Id', ['houseId' => $house]); if (!$house) { Log::info('Returned, didn\'t get the house id'); return; } $this->applyBattleProgress($battleMode, $house); if ($battleMode->battle_xp >= $battleMode->target_xp) { $this->transitionBattlePhase($house, $battleMode); } if ($this->isBattleTime($battleMode)) { $this->triggerBattle($battleMode); } $battleMode->save(); } catch( \Exception $e) { Log::error('Error processing ' . $e->getMessage()); } }
And here is where I dispatch the job from my controller:
PHPpublic function handleBattleProgress($houseId) { Log::info('Dispatching job for houseId: ' . $houseId); HandleBattleProgress::dispatch($houseId); return response()->json(['message' => 'Battle progress is being handled']); }
I have set my environment to use the database driver:
PLAINTEXTQUEUE_CONNECTION=database
However, when I run the commands:
BASHphp artisan queue:listen INFO Processing jobs from the [default] queue. php artisan queue:work INFO Processing jobs from the [default] queue.
I only see these informational messages and no log output from the job. Any ideas why my logs aren’t being displayed?
Comments 0
•Answers 2
•Views 40
Answer by TychoAI Agent • 1 month ago
Below is a checklist of things to verify when your dispatched job isn’t writing logs as expected:
BASHphp artisan queue:restart
BASHphp artisan queue:work
should pick up the job once it’s dispatched. Make sure that no job is “stuck” or waiting due to a misconfiguration in your config/queue.php
.
.env
has a LOG_CHANNEL (or LOG_LEVEL) that isn’t filtering out INFO messages. For instance:ENVLOG_CHANNEL=stack LOG_LEVEL=debug
BASHphp artisan queue:table php artisan migrate
$houseId
) is properly set in the job’s constructor. With proper serialization (using the traits like SerializesModels
) the property should be available in handle()
. If the property isn’t being set, the log message might not show the expected value.By checking these points, you can usually track down why your job isn’t outputting logs. Most often, it comes down to the worker not being restarted after code changes or the log configuration filtering out the messages.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
Answer by NebulousWayfarer039 • 1 month ago
Laravel logs are usually stored in storage/logs/laravel.log. Check if the logs are being written there:
BASHtail -f storage/logs/laravel.log
If logs are missing, ensure the logging configuration in your .env file is correctly set:
BASHLOG_CHANNEL=stack LOG_LEVEL=debug
If it's set to error
, change it to debug
to capture all log levels.
No comments yet.
No comments yet.