Skip to content
Halil Coşdu edited this page Apr 16, 2024 · 1 revision

Laravel S3-compatible log system.

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

Laravel LogWeaver

Laravel LogWeaver is a PHP package designed to provide a simple and flexible way to log events in your Laravel application. It offers a fluent interface for creating logs, allowing you to easily specify the log level, resource, content, and storage disk.

Features

  • Fluent Interface: Easily create logs with a fluent, chainable interface.
  • Multiple Log Levels: Supports different log levels including 'info', 'warning', 'error', and 'critical'.
  • Resource Specification: Specify the resource of the log, such as 'system' or 'event'.
  • Customizable Storage: Choose your storage disk and directory.
  • Parameter Validation: Ensures the validity of log parameters before logging.
  • Array and JSON Conversion: Convert your logs to array or JSON format.
  • Asynchronous Logging: Log events asynchronously with optional waiting for the log to be written to the disk.

Installation

You can install the package via composer:

composer require halilcosdu/laravel-logweaver

You can publish the config file with:

php artisan vendor:publish --tag="logweaver-config"

This is the contents of the published config file:

return [
    'sleep' => env('LOG_WEAVER_SLEEP', 0.5),
];

Usage

$log = LogWeaver::description('User logged in')
    ->logResource('event')
    ->content(['user_id' => 1, 'email' => '[email protected]'])
    ->level('info')
    ->toArray();
$log = LogWeaver::description('System error occurred')
    ->logResource('system')
    ->content(['error' => 'Database connection failed'])
    ->level('error')
    ->log($path, $wait);
$log = LogWeaver::description('Payment gateway down')
    ->logResource('event')
    ->content(['gateway' => 'Stripe', 'status' => 'down'])
    ->level('critical')
    ->log();
$log = LogWeaver::description('Disk space running low')
    ->logResource('system')
    ->content(['disk_space' => '10% remaining'])
    ->level('warning')
    ->toJson();
$log = LogWeaver::description('User registered')
    ->logResource('event')
    ->content(['user_id' => 2, 'email' => '[email protected]'])
    ->level('info')
    ->disk('local')
    ->directory('custom_logs')
    ->log();

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.