smart-contact/smart-log-client

Client for send log to Smart Log Application

v1.0.14 2021-05-24 13:33 UTC

This package is auto-updated.

Last update: 2024-03-24 19:44:43 UTC


README

Latest Version on Packagist Total Downloads License

This is where your description should go. Take a look at contributing.md to see a to do list.

Installation

Via Composer

$ composer require smart-contact/smart-log-client

To publish the config, run the vendor publish command:

php artisan vendor:publish --provider="SmartLogClient\SmartLogClientServiceProvider"

Usage

SmartLogClient::report([
    'level' => 'info', //required
    'level_code' => '', //required
    'status_code' => '',
    'user' => 'John Doe', //required
    'description' => 'New Log Line', //required
    'ip' => 'IP ADDRESS', //required
    'registered_at' => 'Y-m-d H:i:s', //default now()
    'log' => [
        'key' => 'value',
    ],
    'extra' => [
        'key' => 'value',
    ],
    'formatted' => '',
    'user_agent' => 'USER AGENT', //default Jenssegers\Agent::getUserAgent, 
    'browser' => 'BROWSER', //default Jenssegers\Agent::browser
    'browser_version' => 'BROWSER VERSION', //default Jenssegers\Agent::version
    'platform' => 'PLATFORM', //default Jenssegers\Agent::plaform
    'platform_version' => 'PLATFORM VERSION', //default null
]);
SmartLogClient::info([
    'status_code' => '',
    'user' => 'John Doe', //required
    'description' => 'New Log Line', //required
    'ip' => 'IP ADDRESS', //required
    'registered_at' => 'Y-m-d H:i:s', //default now()
    'log' => [
        'key' => 'value',
    ],
    'extra' => [
        'key' => 'value',
    ],
    'formatted' => '',
    'user_agent' => 'USER AGENT', //default Jenssegers\Agent::getUserAgent, 
    'browser' => 'BROWSER', //default Jenssegers\Agent::browser
    'browser_version' => 'BROWSER VERSION', //default Jenssegers\Agent::version
    'platform' => 'PLATFORM', //default Jenssegers\Agent::plaform
    'platform_version' => 'PLATFORM VERSION', //default null
]);

Available Log Level

SmartLogClient::emergency($data);
SmartLogClient::critical($data);
SmartLogClient::error($data);
SmartLogClient::warning($data);
SmartLogClient::notice($data);
SmartLogClient::info($data);
SmartLogClient::debug($data);

Laravel Custom Logging Channel

Apply these changes to the file config/logging.php

'stack' => [
    'driver' => 'stack',
    'channels' => ['smartlog','single'],
    'ignore_exceptions' => false,
],

//Custom Channel
'smartlog' => [
    'driver' => 'custom',
    'handler' => \SmartContact\SmartLogClient\Logging\SmartLogHandler::class,
    'via' => \SmartContact\SmartLogClient\Logging\SmartLogLogger::class
],

Use SmartLog Exceptions Handler

Apply these changes to the file app/Exceptions/Handler.php

namespace App\Exceptions;

class Handler extends \SmartContact\SmartLogClient\Exceptions\Handler
{

}

Track Model's event

Include the Trait SmartContact\SmartLogClient\Traits\TrackingApplicationLogs in the Model that you want to trace

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use SmartContact\SmartLogClient\Traits\TrackingApplicationLogs;

class Order extends Model
{
    use HasFactory, TrackingApplicationLogs;
    
    //Default
    public static $recordEvents = [
        'retrieved', 
        'created', 
        'updated',
        'deleted',
        'restored' // if the model include SoftDeletes trait
    ];
}

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email matteo.meloni@smart-contact.it instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.