Skip to content

Adds logging tap functionality to older Laravel versions

License

Notifications You must be signed in to change notification settings

luka-mladenovic/logging-tap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel logging tap

Adds a logging tap functionality to Laravel versions from 5.0 to 5.3.

Installation

Install the package using Composer.

composer require lukam/logging-tap

Open up config/app.php and add the service provider to your existing providers array.

'providers' => [	
	LoggingTap\LogServiceProvider::class
]

Usage

Create a new logging tap using the artisan make:tap command. This will create a new tap file inside the App\Logging folder.

php artisan make:tap ExampleTap

Open up config/app.php, scroll down to "Logging Configuration" and add a log_tap array entry. Add your logging tap classes to this array. Any classes in this array will customize the Monolog instance when created.

'log_tap' => [App\Taps\ExampleTap::class],

For more information on how to work with logging taps refer to Laravel's logging documentation.

Examples

Create a logging tap to push a processor to Monolog instance:

<?php

namespace App\Logging;
use Monolog\Processor\UidProcessor;

class PushProcessor
{
    public function __invoke($logger, $arguments)
    {
        $logger->getMonolog()->pushProcessor(new UidProcessor);
    }
}

Set Monolog instance formatter:

<?php

namespace App\Logging;

use Monolog\Formatter\LineFormatter;

class Formatter
{
    public function __invoke($logger, $arguments)
    {
        $format = "[%datetime%] - [%level_name%]: %message% %context% %extra%\n";
        $formatter = new LineFormatter($format, null, true, true);

        foreach ($logger->getHandlers() as $handler) {
            $handler->setFormatter($formatter);
        }
    }

Testing

phpunit

License

The MIT License (MIT). See the license file for more information.

About

Adds logging tap functionality to older Laravel versions

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages