使用php时出现问题的monolog doctrine通道日志记录symfony 4
im在独白原则日志记录中有问题(在symfony 5中): framework.yaml:使用php时出现问题的monolog doctrine通道日志记录symfony 4,php,symfony,doctrine,monolog,Php,Symfony,Doctrine,Monolog,im在独白原则日志记录中有问题(在symfony 5中): framework.yaml: monolog: channels: [doctrine_channel] handlers: main: channels: ["!event", "!doctrine_channel"] doctrine: type: service channels: [doctrine_cha
monolog:
channels: [doctrine_channel]
handlers:
main:
channels: ["!event", "!doctrine_channel"]
doctrine:
type: service
channels: [doctrine_channel]
id: app.logger.doctrine_handler
services.yaml:
app.logger.doctrine_handler:
class: App\Util\DoctrineHandler
arguments:
- "@doctrine.orm.entity_manager"
src/Utils/DoctrineHandler.php:
<?
namespace App\Util;
use App\Entity\Logs;
use Doctrine\ORM\EntityManagerInterface;
use Monolog\Handler\AbstractProcessingHandler;
class DoctrineHandler extends AbstractProcessingHandler
{
private $initialized;
private $entityManager;
private $channel = 'doctrine_channel';
public function __construct(EntityManagerInterface $entityManager)
{
parent::__construct();
$this->entityManager = $entityManager;
}
protected function write(array $record): void
{
if (!$this->initialized) {
$this->initialize();
}
if ($this->channel != $record['channel']) {
return;
}
$log = new Logs();
//$log->setMessage($record['message']);
//$log->setLevel($record['level_name']);
$log->setMessage($record['message']);
$log->setLevel($record['level']);
$log->setLevelName($record['level_name']);
$log->setExtra($record['extra']);
$log->setContext($record['context']);
$this->entityManager->persist($log);
$this->entityManager->flush();
}
private function initialize()
{
$this->initialized = true;
}
}
这是不是登录到mysql数据库有什么问题?
提前感谢您提供的所有提示…您需要使用绑定。试试这个指南
这是的,我正在尝试链接中的第一篇文章,但是在symfony 4中,extends AbstractController:$container->get('monog.logger.db')不存在。。。但是以前的控制器是可以工作的…所以使用下面第二个链接中描述的配置。将数据库通道绑定到LoggerInterface$dbLogger var,并使用此var名称注入记录器,就像公共函数someAction(LoggerInterface$dbLogger){}和要注入的确切“db”通道一样。Hi@slmder_h。我在symfony 3.4上也有同样的情况。我将参数@logger传递给我已经完成的自定义服务,比如SlackHandler,在标记上传递通道。在配置文件中,我有[type:service,id:logger.slack]。奇怪的是它没有给我任何错误。不知怎的,这项服务似乎从未被调用过。我试图在monolog处理程序下获取频道的参数,所以我不必在参数下添加新的参数:。。你能帮我理解为什么会这样吗?
// in use inject LoggerInterface $logger
$this->logger = $logger;
$this->logger->info('test');