-
-
Notifications
You must be signed in to change notification settings - Fork 237
Symfony autowiring monolog channels #278
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
Comments
In Symfony 4.2, symfony/symfony#28234 will allow this. (will require a PR here to use registerAliasForArgument()) |
@MaksSlesarenko @nicolas-grekas @Seldaek Hi there! P.S.: Link to the bundle https://github.com/adrenalinkin/monolog-autowire-bundle |
Do someone want to submit a PR since Symfony 4.2 is released? |
@lyrixx Hello Grégoire! |
Hey @adrenalinkin! Your implementation is great, but in 4.2, this is now much easier - should be basically one line of new code - see https://github.com/symfony/symfony/blob/4.4/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L684 for an example This would be awesome to have :) |
Hello, @weaverryan! Thanks you for your opinion, nice to hear that. Correct me if I miss-understand you. Instead of creation different logger decorator classes we will focuses on the parameter names.
monolog:
handlers:
doctrine:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.doctrine.log"
level: info
channels:
- "doctrine"
acme:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.acme_channel.log"
level: info
channels:
- "acme_channel"
<?php declare(strict_types=1);
use Psr\Log\LoggerInterface;
class AcmeLoggerAware
{
/**
* @var LoggerInterface
*/
private $acmeLogLogger;
/**
* @var LoggerInterface
*/
private $doctrineLogger;
public function __construct(LoggerInterface $monologChannelDoctrine, LoggerInterface $monologChannelAcme)
{
$this->acmeLogLogger = $monologChannelAcme;
$this->doctrineLogger = $monologChannelDoctrine;
}
} First QuestionAm I right understand main idea? And one drawback of the implementation described above, in my opinion, - we don't have clear auto-complete in the modern IDE. All programmers should keep in mind specific naming rule. On other side we can generate different logger decorator classes and then we will have useful and clear auto-complete. But drawback, I think, - more difficult realization with code generation. <?php declare(strict_types=1);
use Linkin\Bundle\MonologAutowireBundle\Logger\ChannelAcmeLogLogger;
use Linkin\Bundle\MonologAutowireBundle\Logger\ChannelDoctrineLogger;
use Psr\Log\LoggerInterface;
class AcmeLoggerAware
{
/**
* @var ChannelDoctrineLogger
*/
private $acmeLogLogger;
/**
* @var ChannelDoctrineLogger
*/
private $doctrineLogger;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @param ChannelAcmeLogLogger $acmeLogLogger
* @param ChannelDoctrineLogger $doctrineLogger
* @param LoggerInterface $logger
*/
public function __construct(
ChannelAcmeLogLogger $acmeLogLogger,
ChannelDoctrineLogger $doctrineLogger,
LoggerInterface $logger
) {
$this->acmeLogLogger = $acmeLogLogger;
$this->doctrineLogger = $doctrineLogger;
$this->logger = $logger;
}
} Second QuestionWhat do you think about drawbacks of each implementations and what implementation should we apply? |
Symfony autowiring monolog channels #278
Hi everyone,
While looking for a way to autowire monolog channels, and I got stumbled upon StackOverflow thread where guy named "DrafFter" suggests adding LoggerFactory.
https://stackoverflow.com/questions/43788114/symfony-autowiring-monolog-channels
Maybe this can be implemented within this bundle? Or is there a better way to do autowiring?
The text was updated successfully, but these errors were encountered: