Skip to content

Easily add multiple monolog channels to your Laravel 5.2.* application

License

Notifications You must be signed in to change notification settings

fidelize/multilog

 
 

Repository files navigation

Laravel Multilog

This project is a fork of karlomikus/multilog

Build Status Latest Stable Version License

Easily add multiple Monolog channels to your Laravel or Lumen application.

Install

Via Composer

composer require karlomikus/multilog

Or add the package to your composer file:

"karlomikus/multilog": "2.*"

Next register service provider and facade in your config/app.php file:

// Service provider
Karlomikus\Multilog\MultilogServiceProvider::class
// Facade (optional)
'Multilog' => Karlomikus\Multilog\Facade::class

Configuration

With Laravel, you can publish the configuration file with:

php artisan vendor:publish

If you are using Lumen, please copy the example of configuration file to your application config directory. Then add the following line to bootstrap/app.php:

$app->configure('multilog');

All your channels are defined in config/multilog.php file.

By default you have two channels (request and info):

// Request channel
'request' => function ($channel) {
    $logger = new Logger($channel);
    ...
    return $logger;
},
// Info channel
'info' => function ($channel) {
    $logger = new Logger($channel);
    ...
    return $logger;
}

Usage

Using dependency injection:

use Karlomikus\Multilog\Contracts\MultilogInterface;

private $multilog;

public function __construct(MultilogInterface $multilog)
{
    $this->multilog = $multilog;

    $this->multilog->channel('request')->error('Error here...');
}

Using facade:

Multilog::channel('channel-name')->info('Information here...');

// Channel shorthand is also available
Multilog::c('channel-name')->warning('Warning here...');

Redirecting Log facade calls to a Multilog channel

If you wanna make sure Multilog is used, you can redirect all Log facade calls to Multilog by adding the following service provider:

// Service provider
Karlomikus\Multilog\LogServiceProvider::class

Then configure the default channel in your config/multilog.php file:

'defaultChannel' => 'global',
'channels' => [
    'request' => function ($channel) {
        $logger = new Logger($channel);
        ...
        return $logger;
    },
]

Change log

[2.0.0] - 2017-08-28

  • Change configuration format to use closures
  • Compatibility with Lumen
  • Possibility to redirect Log calls to a Multilog default channel

[1.0.0] - 2016-03-06

  • Initial release

License

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

About

Easily add multiple monolog channels to your Laravel 5.2.* application

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%