Loggers

Configuring a logger

Globally

If you want to replace the default logger you will have to bind an instance in the service container.

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use HappyDemon\SaloonUtils\Logger\Contracts\Logger;
use HappyDemon\SaloonUtils\Logger\Stores\DatabaseLogger;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        $this->app->bind(
            Logger::class, 
            fn (Application $application) => new DatabaseLogger
        );
    }
}

Locally

If you have a special case for a specific connector, you could define which logger to use on the connector itself:

Built in loggers

Database logger

When using the default built-in database logger, you'll have to publish & run migrations;

This logger will store each request in the saloon_requests table.

Be sure to schedule model pruning daily with a cronjob

You are able to overwrite the model class altogether by defining your own model in the saloon-utils.logs.database_model config.

This is the default-bundled model:

https://github.com/happyDemon/saloon-utils/blob/main/src/Logger/SaloonRequest.php

Memory logger

This logger can be helpful when debugging or running tests. It will setup a cache store under saloon-utils with the array driver.

You can retrieve the requests that were sent on the logger itself:

Build your own

You can easily build your own logger and set it as the default.

Ensure your custom logger implements the Logger interface.

Be sure to make use of the HappyDemon\SaloonUtils\Logger\Stores\ParsesRequestData trait when implementing your own logger. It provides helper methods for data conversion and redaction.

https://github.com/happyDemon/saloon-utils/blob/main/src/Logger/Contracts/Logger.php

Last updated