ahmedash95 / laravel-log-writer by ahmedash95

Laravel Package for custom loging files
59
8
2
Package Data
Maintainer Username: ahmedash95
Maintainer Contact: ahmed29329@gmail.com (Ahmed Ashraf)
Package Create Date: 2017-04-21
Package Last Update: 2017-04-21
Language: PHP
License: MIT
Last Refreshed: 2024-04-19 15:09:15
Package Statistics
Total Downloads: 59
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 8
Total Watchers: 2
Total Forks: 3
Total Open Issues: 0

Laravel Custom Log Writer

customize your laravel log into seperated files

Installation

You can install the package via composer:

composer require ahmedash95/logwriter

Next up, the service provider must be registered:

// config/app.php
'providers' => [
    ...
    Ahmedash95\LogWriter\Providers\LogWriterServiceProvider::class,

];

// Register alias
'aliases' => [
    ...
    'LogWriter' => Ahmedash95\LogWriter\Facades\LogWriterFacade::class,
    
];

you must publish the config file for customize log files:

php artisan vendor:publish --provider="Ahmedash95\LogWriter\Providers\LogWriterServiceProvider"

This is the contents of the published file: config/logwriter.php

<?php

use Monolog\Logger;

return [

    /*
     * The base path of log files
     */
    'log_path' => storage_path(),

    /*
     * The Log channels.
     */
    'channels' => [
        'event' => [
            'path'  => 'logs/event.log',
            'level' => Logger::INFO,
        ],
        'audit' => [
            'path'  => 'logs/audit.log',
            'level' => Logger::INFO,
        ],
    ],

    /*
     * The Log levels.
     */
    'levels' => [
        'debug'     => Logger::DEBUG,
        'info'      => Logger::INFO,
        'notice'    => Logger::NOTICE,
        'warning'   => Logger::WARNING,
        'error'     => Logger::ERROR,
        'critical'  => Logger::CRITICAL,
        'alert'     => Logger::ALERT,
        'emergency' => Logger::EMERGENCY,
    ],

];

Available methods

Log to file

The easiest way to log info in the file is to use write method

LogWriter::write('event','This is log line into event file');

log levels

Also you can use defferent types that definted in levels list

LogWriter::alert('event','Using log levels');
// or
LogWriter::warning('event','Using log levels');

Credits

License

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