Laravel logging not working from job handle method

Viewed 2700

I can't log anything from my Job's handle method, with the Log facade. Logging from controller or other part of the application with this facade works fine.

I have tried the solution here : Logging not working in laravel queue job, but it does not work with Laravel 6.17, and here : https://stackoverflow.com/a/55206727/10767428 , but it does not affect behaviour in any way.

  • PHP 7.2
  • Laravel 6.17
  • APP_ENV=local
  • APP_LOG_LEVEL=debug
  • Laravel runs inside Docker with Alpine image and other stuff unrelated

Here is my job :

class MyJob implements ShouldQueue
{
    use Dispatchable;
    use InteractsWithQueue;
    use Queueable;
    use SerializesModels;

    public function handle()
    {
       Log::warning("HI");
    }
}

The Job is correctly handled when I dispatch if, but nothing shows up in my storage/app/logs/laravel.log.

This file and the entire folder storage has 777 permissions.

I use "single" driver in config/logging.php :

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
        ],

Any ideas?

EDIT 07/17/2020

As requested, here is my config.horizon.php :

https://pastebin.com/jkQLcDKF

EDIT 07/20/2020

I can log from the same job when I use dipatchNow method to call it, instead of dispatch one. Any ideas why ?

2 Answers

If your queue is running on Supervisor, your log would be in the Supervisor logs. Share your queue/supervisor configuration if you're not able to find it. You could also check your docker logs as well.

If anyone else is having issues, Horizon has to be restarted when changes are made to the jobs. Otherwise, the job that runs will not reflect your code changes.

This is regardless of the environment. That's why it's a good idea to restart horizon when you re-deploy to the server.

Related