【发布时间】:2021-08-03 09:31:45
【问题描述】:
我正在使用带有 API 平台、docker-compose 和 Twilio 的 Symfony 5,并且我正在使用 SMS 消息传递功能。
所以在我的 Twilio 控制台中,在 SMS 回调中,我输入了我用 ngrok 打开的路由:https://f64560c9efff.ngrok.io/twilio/intervention/request/response
要查看 Twilio 响应的内容,我想实现一个记录器
所以我安装了monolog并实现了conf文件packages/dev/monolog.yaml:
monolog:
channels: ['twilio']
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ["!event"]
# uncomment to get logging in your browser
# you may have to allow bigger header sizes in your Web server configuration
#firephp:
# type: firephp
# level: info
#chromephp:
# type: chromephp
# level: info
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine", "!console"]
twilio:
type: stream
path: '%kernel.logs_dir%/twilio.log'
channels: [ 'twilio' ]
我在api/var/log/ 中创建了一个twilio.log 文件,并使用chmod 777 进行测试
在我的控制器中我正在做:
private $em;
private $twilioLogger;
public function __construct(EntityManagerInterface $em,LoggerInterface $twilioLogger)
{
$this->em = $em;
$this->twilioLogger = $twilioLogger;
}
/**
* @Route("/twilio/route", name="twilio_route")
*/
public function twilioRoute(Request $request): Response
{
$answer = new Answer();
$answer->setResponse($request->getContent());
$answer->setResponseAt(new DateTimeImmutable());
$this->twilioLogger->info("WE PASS HERE");
$this->twilioLogger->info($request->getContent());
$this->em->persist($answer);
$this->em->flush();
return new Response(Response::HTTP_OK);
}
所以我知道 Twilio 的回调通过了,因为对象 Answer 只保留了 responseAt 字段
但是我的twilio.log 文件是空的,我不明白为什么记录器没有写入它
我错过了一个配置还是错过了什么?
如果有人有想法或线索,我将不胜感激!
谢谢!
【问题讨论】:
标签: symfony logging callback twilio monolog