symfony - Symfony 记录器无法写入日志文件
问题描述
我正在使用带有 API 平台、docker-compose 和 Twilio 的 Symfony 5,并且正在使用 SMS 消息传递功能。
因此,在我的 Twilio 控制台中,在 SMS 回调中,我输入了使用 ngrok 打开的路由:https://f64560c9efff.ngrok.io/twilio/intervention/request/response
要查看 Twilio 响应的内容,我想实现一个记录器
所以我安装了独白并实现了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' ]
我已经创建了一个twilio.log
文件api/var/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
文件是空的,我不明白为什么记录器没有写入
我错过了一个配置还是我错过了什么?
如果有人有想法或线索,我将不胜感激!
谢谢!
解决方案
我没有做任何与你不同的事情。然而,有一件事确实很突出:
我在 api/var/log/ 中创建了一个 twilio.log 文件
默认情况下,日志文件是在var/log
not in中创建的api/var/log
。当我模拟一个简单的示例时,该文件是为我创建的并包含相关的日志消息。我希望这个对你有用。
推荐阅读
- c# - Winform mssql多表更新c#
- python - 使用 configparser 解析 ini 文件会给出 configparser.MissingSectionHeaderError 与 'ÿþ\n' 作为第一行
- c# - 绑定“找不到 CLR 属性”时出现 Avalonia UI 错误
- angular - 类型 'string' 不可分配给类型 'ArrayBuffer | 类数组
| 共享数组缓冲区' - java - 在 IBM Notes 中获取日期范围内的文档
- charts - Highchart - xAxis 每周日期可以从给定日期开始吗?
- c# - json数组解析错误,应用程序完成而没有读取整个请求体
- spring-boot - 在反向代理后面使用 OAuth2 的 Spring Boot
- kubernetes - kubectl 等待 --for=condition=complete --timeout=30s
- excel - Excel.Application:Microsoft Excel 无法访问文件 '[
]'有几个可能的原因: