Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] More flexibility for custom log drivers #23184

Merged
merged 1 commit into from
Feb 16, 2018
Merged

Conversation

GrahamCampbell
Copy link
Member

@GrahamCampbell GrahamCampbell commented Feb 15, 2018

I love the ability to have custom log drivers in config, without needing to call extend on drivers, and it reminded me of something very similar I was doing in an app as a way of specifying lazy values in config, by using callables (in particular, using the array notation since we cannot serialize closures).

So, the example at https://laravel.com/docs/5.6/logging#creating-custom-channels is great, and still works, but the following example now works also:

'channels' => [
    'custom' => [
        'driver' => 'custom',
        'via' => [App\Logging\MyCustomLogger::class, 'make'],
    ],
],

with a static function:

<?php

namespace App\Logging;

use Monolog\Logger;

class MyCustomLogger
{
    public static function make(array $config)
    {
        return new Logger(...);
    }
}

This is very simple, and you don't need to go through the service container. Moreover, you don't need to create a special class with an invoke method, you can just add a static method wherever you feel, even on the logger class itself.

@sisve
Copy link
Contributor

sisve commented Feb 16, 2018

Perhaps add a test?

@taylorotwell taylorotwell merged commit 71d7be9 into 5.6 Feb 16, 2018
@taylorotwell taylorotwell deleted the custom-log-callable branch February 22, 2018 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants