Skip to content

Async logging does not work #1058

Description

@LevineLighto

PHP Version

^8.3

Laravel Version

13.x

Package Version

14.0.5

Description

Hello!
After updating the package earlier this morning, the audit stopped working

Context:

  • Logging configured to run asynchronously using queue
  • Data changes from job & schedules are ignored

Problem:

  • Audit job dispatched, but no data is recorded unless the console config in config/audit.php file is true

What I found:
I feel like the change in ProcessDispatchAudit.php at 4fb70d2 was pretty questionable?
Image
It calls the static method Auditable::isAuditingEnabled() that also checks whether the audit.console is true whenever the app is running via queue. Meanwhile the ProcessDispatchAudit is processed using queue in asynchronous configuration.

Steps To Reproduce

  1. Clone this repo
  2. Install & configure laravel env
    composer install
    cp .env.example .env
    php artisan key:generate
    // Fill database information on .env before continuing
    php artisan migrate
  3. Start the app
    php artisan serve
    
  4. Start a queue worker
    php artisan queue:work
    -- or
    php artisan queue:listen
  5. Access the app
    http://localhost:8000
  6. Input user name and press enter
  7. The user panel will refresh with a new entry, but audit panel remains empty
  8. Go to config/audit.php, change console value to true
    (please restart your queue worker if you used php artisan queue:work)
  9. Go back to your browser
  10. Do step 6
  11. The user panel will refresh with a new entry, and audit panel should have a new entry (you may need to refresh the audit panel to see the new entry, the audit panel automatically refreshes every 5 seconds)

Possible Solutions

Change the handle method in ProcessDispatchAudit.php to something like this?

public function handle(DispatchAudit $event): void
{
    if (!Config::get('audit.enabled', true)) {
        return;
    }
    Auditor::execute($event->model);
}

Anyway, thank you for your great work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions