devraeph/laravel-alh

Another Logging Helper for Laravel

0.2.0 2023-03-30 14:17 UTC

This package is auto-updated.

Last update: 2024-04-30 00:51:31 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Another small and simple logging package. Mostly I created this for my self and wanted to simplify logging stuff for my ongoing projects.

If anyone can make use of this you're welcome to contribute or open an issue.

Installation

You can install the package via composer:

composer require devraeph/laravel-alh

You can install the package with:

php artisan alh:install

OR manually

You can publish and run the migrations with:

php artisan vendor:publish --tag="laravel-alh-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="laravel-alh-config"

This is the contents of the published config file:

return [
    'logging' => [
        'in_productions' => env("ALH_LOG_IN_PRODUCTION",false),
        "to_database" => env("ALH_TO_DB",false),
        "to_file" => env("ALH_TO_FILE",true),
        "file_driver" => env("ALH_FILE_DRIVER","local"),
        "file_path" => env("ALH_FILE_PATH","logs_alh"),
        "separate_by_type" => env("ALH_SEPARATE_BY_TYPE",false),
    ],
    'general' => [
        "clear_logs" => false,
        'retention' => env("ALH_LOG_RETENTION",7), //Keep Logs for 7 days by default
    ],

];

Optionally, you can publish the views using

php artisan vendor:publish --tag="laravel-alh-views"

Usage

  /*
   * Uses default mechanism
   * configured in config/alh.php
   * default only toFile and not in production
   */
   
   ALH::error("Error message",new Exception("ex"));
   ALH::warning("Warning message",new Exception("ex"));
   ALH::info("Info message");
   ALH::success("Success message");
   ALH::pending("Pending message");

   /*
   * Override config settings
   */

   /* Log Only to DB */
   ALH::toDB()->error("Error message",new Exception("ex"));
   /* Log only to File */
   ALH::toFile()->error("Error message",new Exception("ex"));
   /* Force Log both */
   ALH::toDB()->toFile()->error("Error message",new Exception("ex"));

   /*
   * Option to set Log issuer like User
   */
   ALH::setIssuer(User::first())->error("Error message",new Exception("ex"));

Access DB Logs

Dashboard at /alh-logs

The gate definition is similar to laravel/horizon.

You can change the defaults at app/Providers/ALHMainServiceProvider.php

protected function gate(): void
{
    Gate::define('viewALH', function (User $user) {
        return in_array($user->email, [
            //
        ]);
    });
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.