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.5] Feature: configurable logger channel name #20133

Merged

Conversation

ralphschindler
Copy link
Contributor

Monolog (unfortunately) does not allow post-instantiation of the base logger to change the Monolog::$name. This makes it impossible to change the name away from the environment specified one inside configureMonologUsing without a significant amount of code using reflection.

This patch is non-intrusive, and only introduces the ability to use app.log_channel if it is set by the user (this is a similar workflow to app.log_maxfiles.

References on others having the same problem:

Sample code required to change the name after instantiation:

       $this->app->configureMonologUsing(function (Logger $logger) {
            $r = new \ReflectionObject($logger);
            $name = $r->getProperty('name');
            $name->setAccessible(true);
            $name->setValue($logger, env('APP_NAME'));
            ...

(If you should require a test, I would be more than happy to create one, but I noticed ServiceProviders don't normally have tests in the test suite.)

- add ability to configure logger channel name
@@ -46,6 +46,12 @@ public function createLogger()
*/
protected function channel()
{
if ($this->app->bound('config')) {
if ($channel = $this->app->make('config')->get('app.log_channel', null)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

, null is useless here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, I can remove it if y'all would like.

@taylorotwell taylorotwell merged commit a29a271 into laravel:master Jul 18, 2017
@ralphschindler ralphschindler deleted the configurable-log-channel-name branch July 18, 2017 18:42
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