Skip to content
This repository has been archived by the owner on Dec 9, 2020. It is now read-only.

Many changes #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

alanwillms
Copy link

Hi @karlomikus

This PR adds the following changes:

  • Compatibility with newer versions of Laravel and Lumen
  • Wildcard channels. For example, you could make both Multilog::channel('industries.acme') and Multilog::channel('industries.umbrella') instantiate the logger based on the industries.* channel configuration in config/multilog.php
  • Log::something() can be proxied to Monolog::channel($defaultChannel)::something(), so that all previous or third party log calls go through Multilog
  • Now Multilog channels are configured using closures instead of arrays. This adds flexibility, but drops the easiness of using arrays to configure the logger.

I am not sure you will merge this PR because I have substantially changed the way config/multilog.php works, but I hope you give it a try and think about merging it and tagging as a new version.

This is a real world example with names changed:

<?php
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;

return [
    'defaultChannel' => 'app',
    'channels' => [
        'app' => function ($channel) {
            $logger = new Logger($channel);
            $logger->pushHandler(new RotatingFileHandler(
                storage_path('/logs/app.log'),
                7,
                Logger::INFO
            ));

            if (env('APP_DEBUG', false)) {
                $logger->pushHandler(new RotatingFileHandler(
                    storage_path('/logs/debug.log'),
                    7,
                    Logger::DEBUG
                ));
            }

            return $logger;
        },
        'industries.*' => function ($channel) {
            $logger = new Logger($channel);
            $logger->pushHandler(new RotatingFileHandler(
                storage_path('/logs/' . $channel . '.log'),
                7,
                Logger::DEBUG
            ));

            return $logger;
        },
    ]
];

…s possible to redirect Log calls to Multilog
@karlomikus karlomikus self-assigned this Sep 4, 2017
$logger->pushHandler($handler);

$this->channels[$channel] = $logger;
$this->channels[$channel] = $closure($channel);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of forcing to a closure, pass as a parameter, but delegate to a handler.

$this->channels[$channel] = $config instanceof \Closure ? $config($channel) : $this->handle($config);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants