Skip to content

Set custom logger #287

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

Closed
kaanbasal opened this issue Dec 6, 2017 · 6 comments · Fixed by #289
Closed

Set custom logger #287

kaanbasal opened this issue Dec 6, 2017 · 6 comments · Fixed by #289
Labels

Comments

@kaanbasal
Copy link

$extensions = [new LoggerExtension(new ConsoleLogger($output))];

I am trying to set my custom logger which implements and registered for LoggerInterface, using LoggerExtension but because of this line is setting logger it gives me this error:
The logger modification is not allowed

Can you please explain how can I set my custom logger?

@makasim
Copy link
Member

makasim commented Dec 6, 2017

Honestly, I don't know. We should find out a solution. Feel free to propose

@makasim
Copy link
Member

makasim commented Dec 6, 2017

@kaanbasal by design it should be possible to change logger Extension::onStart method, which is not at the moment. has to be fixed.

@kaanbasal
Copy link
Author

kaanbasal commented Dec 6, 2017

I think the problem is hardcoding the 'new ConsoleLogger()' to the command itself. Instead of doing this way, LoggerInterface can be injected and used in the command.

On the other hand, IMO the proper way is adding configuration to support 'logger_extension'. In this case you can check if this extension is enabled and if so you can add it.
@makasim wdyt?

@makasim
Copy link
Member

makasim commented Dec 6, 2017

The LoggerExtension should set a logger only if it was not set. https://github.com/php-enqueue/enqueue-dev/blob/master/pkg/enqueue/Consumption/Extension/LoggerExtension.php#L34

So you should be able to register your own LoggerExtension with a logger you want before the one created in the command itself. It should just work cuz default loggers are called before runtime ones.

@makasim makasim added the bug label Dec 6, 2017
@kaanbasal
Copy link
Author

kaanbasal commented Dec 6, 2017

I did the same thing, and yes it sets the logger, but after that command is also trying to set the logger and it throws the exception mentioned earlier.

The logger modification is not allowed

edit: Btw I solved it by extending the command with the logger injection and removing the line. But it is a bit hacky solution

@makasim
Copy link
Member

makasim commented Dec 6, 2017

The LoggerExtension should set a logger only if it was not set. https://github.com/php-enqueue/enqueue-dev/blob/master/pkg/enqueue/Consumption/Extension/LoggerExtension.php#L34

This line has to be fixed

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

Successfully merging a pull request may close this issue.

2 participants