laravel - 创建文件后记录丢失几行
问题描述
我写了一个特征来记录一些东西,但是当第一次使用它来记录时(文件不存在),一些日志内容看起来像是丢失了。
试了几次调试,没有解决。
帮手特质
<?php
namespace App\Helpers;
use Illuminate\Support\Facades\Log;
trait OutToLog
{
public function outLogTo(string $channel, string $logContents)
{
Log::channel($channel)->info($logContents);
}
}
预期日志
[2019-10-20 19:19:42] INFO: status=200;
request=test_request;
response=test_response;
[2019-10-20 19:19:42] INFO: status=300;
request=test_request;
response=test_response;
[2019-10-20 19:19:42] INFO: Test notify service with exception.
真正的日志
[2019-10-20 19:19:42] INFO: Test notify service with exception.
=test_response;
经过第一次测试,第二次测试,之后没有同样的问题。实在不明白为什么。
这被称为如下所示:
private function resultLog(array $result): void
{
if ($result['status'] === 200) {
doSomething...
}
$resultLog = "status=" . $result['status'] . $resultRequest . ";\n" .$resultResponse. "\n";
$this->outLogTo('channel_name', $resultLog);
}
这被称为
try {
$this->resultLog($result);
} catch (\Exception $e) {
$this->exceptionLog($e);
}
像这样的异常日志
private function exceptionLog($e){
$this->outLogTo('channel_name', $e);
}
解决方案
推荐阅读
- javascript - 为什么 Firebase 动态链接的 longDynamicLink 参数中链接中的编码空格字符 (%20) 更改为 %2B
- java - 发送 Amazon Textract 请求时导致错误的通知处理程序
- angular-cli - 生成角度项目时出现问题
- amazon-web-services - aws sns - 处理 SMS 传递失败
- powerbi - 当包含超过一年的数据月度数据时,聚集柱形图条会被压扁
- javascript - 新用户的 Firebase 数据库安全性
- javascript - 将 API 数据附加到数组中
- swift - 无法在可编程约束之间切换
- json - How to update a nested array in JSON in mssql
- r - 在 ggplot2 中使用线型和颜色示例作为轴标签